html - How can I display my plot without toolbars, in Shiny? -
this question extension of this question.
i plotting rather large gglot in shiny.
using renderplot(width = 1500, height = 1000, ...
able show whole plot; however, have scrollbar on right. extend height of column in fluidrow, rather have scrollbar.
from understand, shiny (aka bootstrap) should dynamically size height of fluidrow whatever size of plot is. why visible area small? scrollbars nice, want whole plot visible.
ui.r
source("helper.r") shinyui(fluidpage(theme='test.css', fluidrow( column(2, fluidrow( h3("select customer:"), wellpanel(class="info", numericinput(inputid="num", label="select id:", value=nan), if(show_age_slider=='yes'){textoutput("")}, if(show_edu_slider=='yes'){textoutput("")}, if(show_gender_buttons=='yes'){textoutput("")} ))), #do.call call navbarpage function arguments in tabs list shinyui(fluidrow( column(12, "", do.call(navbarpage,tabs) ))))))
server.r
library("shiny") library("ggplot2") df_for_plotting <- structure(list(col1 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), col2 = c(100, 100, 61.9433678425096, 10.7823906941804, 4.18175346165306, 3.24251454697229, 6.68573373055455, 14.945119260922, 18.9296271776082, 11.0742379220636 ), col3 = c(100, 100, 100, 12.8418470680653, 5.31239161296286, 4.42025167250118, 10.699998838647, 27.5067118056336, 20.6360723198699, 13.1476876837599), col4 = c(100, 100, 100, 100, 100, 100, 100, 100, 100, 100)), .names = c("col1", "col2", "col3", "col4"), row.names = c("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"), class = "data.frame") hex=c("#cc0000", "#90bd31", "#178ccb") textsize=c(8) ############## shiny server starts here: ####################################################################### shinyserver(function(input, output) { # begin observe() block observe( lapply(seq(1:number_of_tabs),function(i) output[[paste0("plot",i)]] <- renderplot(width = 1500, height = 1000,{ #<-- lapply fill each tab , create 1 ggplot plotindex <<- 0 list_of_ggplots <<- list() #although have 1 tab, extend having multiple tabs p <- ggplot() breaks=c(0, 25, 50, 75, 100, 115, 130) break_labels=c("0%", "25%", "50%", "75%", "100%") number_of_variables <- 10 ### inner loop (varnum in seq(1:number_of_variables)){ #<-- need make 3 segments 3 variables tab p <- p + scale_y_discrete(breaks = seq(10), labels = c("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten")) p <- p + geom_segment(data=df_for_plotting, aes_q(x=df_for_plotting$col1[varnum], xend=df_for_plotting$col2[varnum]-0.001, y=varnum, yend=varnum, colour='impaired'), size=textsize*2.5) + geom_segment(data=df_for_plotting, aes_q(x=df_for_plotting$col2[varnum], xend=df_for_plotting$col3[varnum]-0.001, y=varnum, yend=varnum, colour='normal'), size=textsize*2.5) + geom_segment(data=df_for_plotting, aes_q(x=df_for_plotting$col3[varnum], xend=df_for_plotting$col4[varnum]-0.001, y=varnum, yend=varnum, colour='optimal'), size=textsize*2.5) p <- p + scale_color_manual(values=c(impaired=hex[1], normal=hex[2], optimal=hex[3], white='#ffffff'), name="function key") # p <- p + theme(plot.margin=unit(c(0,0,0,0), "cm")) # p <- p + theme(panel.margin=unit(c(0,0,0,0), "cm")) list_of_ggplots[["to_ui"]] <<- p # strange true; apparently arbitrary key works inserting plot list_of_ggplots } print(list_of_ggplots) #<-- send out ui }) ) ) #<-- end of observe function } #<-- end of brace in shinyserver function ) #<-- end shinyserver function
helper.r
show_gender_buttons='no' show_edu_slider='no' show_age_slider='no' ############################################## ### part create ui ### #tab_names <- c("", tab_names) #make list of arguments want pass navbarpage function tabs<-list() #first element title, empty in our case tabs[[1]]="" #add tabpanels list (j in 2:(number_of_tabs+1)){ tabs[[j]]=tabpanel(tab_names[j],plotoutput(paste0("plot",j-1)))} ################################################
you didn't post theme.css
, issue css overflow
argument set scroll
div
holding plots in app's css. forces scrollbars if div small content.
the default height
plotoutput
set 400px, in renderplot
if set height 1000 scrollbar if overflow of div set scroll.
try setting height argument of plotoutput
1000px or more example:
#add tabpanels list (i in 2:(number_of_tabpages+1)){ tabs[[i]]=tabpanel(paste0("tab",i-1),plotoutput(paste0("plot",i-1),height="1100px")) }
should give this:
you can try finding sets overflow
scroll
div. i'm suspecting because when code run without theme.css
looks fine without changing code.
Comments
Post a Comment