如何显示我的情节没有工具栏,在闪亮? [英] How can I display my plot without toolbars, in Shiny?

查看:112
本文介绍了如何显示我的情节没有工具栏,在闪亮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是这个问题的扩充问题。

我在Shiny绘制了一个相当大的gglot。

I am plotting a rather large gglot in Shiny.

使用 renderPlot(width = 1500,height = 1000,... ;但是,我现在在右边有一个滚动条,我想在fluidRow中扩展列的高度,而不是这个滚动条。

Using renderPlot(width = 1500, height = 1000, ... I am able to show the whole plot; however, I now have a scrollbar on the right. I would like to extend the height of the column in the fluidRow, rather than have this scrollbar.

根据我的理解,Shiny bootstrap)应该动态地将fluidRow的高度调整为任何图的大小,为什么我的可见区域这么小?滚动条很好,但我想要整个图是可见的。

From what I understand, Shiny (aka bootstrap) should dynamically size the height of the fluidRow to whatever the size of the plot is. Why is my visible area so small? Scrollbars are nice, but I want the whole plot to be 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 will call the navbarPage function with the arguments in the 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 the observe() block
observe(


lapply(seq(1:number_of_tabs),function(i) output[[paste0("plot",i)]] <- renderPlot(width = 1500,
                                                                                  height = 1000,{   #<-- lapply will fill up each tab and create one ggplot

  plotindex <<- 0
  list_of_ggplots <<- list() #although we only have one tab, we could easily extend to 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
  for (varnum in seq(1:number_of_variables)){ #<-- We need to make all three segments for all three variables for this 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 # this is strange but true; apparently any arbitrary key works for inserting the plot into the list_of_ggplots
}   
      print(list_of_ggplots)  #<-- to send out to UI
})
)


) #<-- end of observe function
}  #<-- end of brace in shinyserver function
)  #<-- end the shinyserver function

helper.R

show_gender_buttons='No'
show_edu_slider='No'
show_age_slider='No'
##############################################
### this part is to create the UI properly ###

#tab_names <- c("", tab_names)
#make a list of all the arguments you want to pass to the navbarPage function
tabs<-list()


#first element will be the title, empty in our case
tabs[[1]]=""

#add all the tabPanels to the list
for (j in 2:(number_of_tabs+1)){
     tabs[[j]]=tabPanel(tab_names[j],plotOutput(paste0("plot",j-1)))}

################################################


推荐答案

你没有发布你的 theme.css ,但问题可能是css overflow 参数设置为滚动为 div 拿着你的应用程序的CSS中的地块。如果div对于其内容太小,则强制滚动条。

You didn't post your theme.css, but the issue is probably that the css overflow argument is set to scroll for the div holding the plots in you app's css. This forces scrollbars if the div is too small for its content.

默认 height plotOutput 设置为400px,因此在你的 renderPlot 中如果你设置高度为1000,你会得到一个滚动条,如果溢出的div

The default height for a plotOutput is set to 400px, so in your renderPlot if you set the height to 1000 you will get a scrollbar if the overflow of the div is set to scroll.

尝试将 plotOutput 的高度参数设置为1000像素或更多,例如:

Try setting the height argument of plotOutput to 1000px or more for example:

#add all the tabPanels to the list
for (i in 2:(number_of_tabPages+1)){
  tabs[[i]]=tabPanel(paste0("Tab",i-1),plotOutput(paste0("plot",i-1),height="1100px"))

}

应该这样:

img src =https://i.stack.imgur.com/aUMDM.pngalt =enter image description here>

您也可以尝试寻找为此div设置 overflow 滚动。我只是怀疑这是因为当代码运行没有 theme.css 它看起来没有更改您的代码。

You can also try finding what sets the overflow to scroll for this div. I'm just suspecting this because when the code is run without the theme.css it looks fine without changing your code.

这篇关于如何显示我的情节没有工具栏,在闪亮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆