2017-02-21 56 views
0

总的来说,我的目标是在灰色框中包含一组UI元素。这纯粹是一种审美的东西,我用sidebarPanel()来试图完成它。sidebarPanel没有调整大小plotOutput

我在shiny一个mainPanel内使用sidebarPanel()时碰到对我的UI布局的问题。它看起来好像sidebarPanel()更改页面上的图和其他UI元素之间的间距。我已经包含下面重复的例子:

library(shiny) 
library(ggplot2) 

server <- function(input, output, session) { 
    ###Outputting data exploration graph 
    output$graphMain <- renderPlot({ 
    ggplot(data=mtcars) + geom_histogram(aes(x=hp)) 
    }) 
} 

ui <- pageWithSidebar(
    headerPanel = NULL,sidebarPanel = NULL, 
    mainPanel = mainPanel(
    tabsetPanel(
     type = "pills", 
     tabPanel("My Panel", 
       sidebarPanel(width=12 ####Problematic sidebarPanel 
          , checkboxInput(inputId="checkbox1",label="Check box 1") 
       ), 
       plotOutput("graphMain", width = "95%") 
       ,checkboxInput(inputId="checkbox2",label="Check Box 2") 
    ) 
    ) 
) 
) 

shinyApp(ui = ui, server = server, options = list(launch.browser = T)) 

下面显示了问题的红色圆圈强调: enter image description here

我挖远一点到这一点,并注意到这个问题似乎局限于与以重叠plotOutput()是唯一的。例如,我试图用dataTableOutput()替换我的,问题就消失了。

我的问题是:有没有快速解决这个问题?我知道我可以通过添加一堆br()来修复它,但我想避免这种情况。另外,如果有更好的方法将一组输入放入灰色框中,请让我知道!

回答

1

将这工作给你:

server <- function(input, output, session) { 
    ###Outputting data exploration graph 
    output$graphMain <- renderPlot({ 
    ggplot(data=mtcars) + geom_histogram(aes(x=hp)) 
    }) 
} 

ui <- pageWithSidebar(
    headerPanel = NULL,sidebarPanel = NULL, 
    mainPanel = mainPanel(
    tabsetPanel(
     type = "pills", 
     tabPanel("My Panel", 
       sidebarPanel(width=12 ####Problematic sidebarPanel 
          , checkboxInput(inputId="checkbox1",label="Check box 1") 
       ), 
       fluidRow(verticalLayout(plotOutput("graphMain", width = "95%") 
       ,checkboxInput(inputId="checkbox2",label="Check Box 2")))) 
    ) 
    ) 
) 
) 

shinyApp(ui = ui, server = server, options = list(launch.browser = T)) 
+0

完美,伟大工程! –