【问题标题】:Shiny: How to increase the width of tabsetPanel to cover the whole area to the right of the sidebarPanel?Shiny:如何增加tabsetPanel的宽度以覆盖sidebarPanel右侧的整个区域?
【发布时间】:2016-06-06 03:36:55
【问题描述】:

我想创建一个闪亮的应用程序,其中有一个 sidebarPanel 和 tabesetPanel。

我使用下面的代码创建了应用程序

library(shiny)
library(ggplot2)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h1("Shiny app"), 
tags$hr(),
h2("several options here"), 
width =2),
mainPanel(uiOutput("tb"))
)
)
server <- function(input,output){
output$diamonds1 <- renderPlot({
ggplot(diamonds, aes(x=carat, y=price, col=clarity)) + 
                     geom_point(alpha=0.5)+ facet_wrap(~color, scales="free")
})
output$diamonds2 <- renderPlot({
ggplot(diamonds, aes(x=carat, y=price, col=clarity)) + 
                     geom_point(alpha=0.5)+ facet_wrap(~cut, scales="free")
})
output$info <- renderPrint({
nearPoints(diamonds, input$plot_click, threshold = 10, maxpoints = 1,
           addDist = TRUE)
})    
output$tb <- renderUI({
tabsetPanel(tabPanel("First plot", 
                     plotOutput("diamonds1")),
            tabPanel("Second plot", 
                     plotOutput("diamonds2", click = "plot_click"), 
                     verbatimTextOutput("info")))      
})
}
shinyApp(ui = ui, server = server)  

我希望 tabsetPanel 覆盖 sidebarPanel 右侧的整个区域。

按照the answers of this question的建议,我尝试了以下

div(, class ="span12") 

),  style='width: 1000px;)

但是,tabset 面板和绘图仍然没有覆盖 sidebarPanel 右侧的整个区域。

有什么建议吗?

更新

感谢@K。罗德的回答,情节现在覆盖了侧边栏面板旁边页面的整个高度,但仍然没有覆盖整个宽度

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    编辑:很抱歉没有检查我的第一个答案。但这里有一些可行的方法:

    由于某种原因,plotOutput 被破坏,因为height = "100%" 不起作用,否则这将是一个解决方案。但是您可以手动添加 css3,它会根据窗口大小使用...vh 缩放您的绘图。

    代码:

    library(shiny)
    library(ggplot2)
    ui <- fluidPage(
      sidebarLayout(
        sidebarPanel(
          h1("Shiny app"), 
          tags$hr(),
          h2("several options here"), 
          width =2),
        mainPanel(
          uiOutput("tb")
        )
      )
    )
    server <- function(input,output, session){
      output$diamonds1 <- renderPlot({
        ggplot(diamonds, aes(x=carat, y=price, col=clarity)) + 
          geom_point(alpha=0.5)+ facet_wrap(~color, scales="free")
      })
      output$diamonds2 <- renderPlot({
        ggplot(diamonds, aes(x=carat, y=price, col=clarity)) + 
          geom_point(alpha=0.5)+ facet_wrap(~cut, scales="free")
      })
      output$info <- renderPrint({
        nearPoints(diamonds, input$plot_click, threshold = 10, maxpoints = 1,
                   addDist = TRUE)
      })    
      output$tb <- renderUI({
        tabsetPanel(
          tabPanel("First plot", 
                             tags$head(tags$style(type = "text/css", "#diamonds1 {height:95vh !important;}")),
                             plotOutput("diamonds1")),
                    tabPanel("Second plot", 
                             tags$head(tags$style(type = "text/css", "#diamonds2 {height:80vh !important;}")),
                             plotOutput("diamonds2", click = "plot_click"), 
                             verbatimTextOutput("info")))      
      })
    }
    shinyApp(ui = ui, server = server)  
    

    我承认,这更像是一种解决方法。

    【讨论】:

    • 感谢您的时间和帮助。尽管如此,tabset 面板和绘图并未覆盖 sidebarPanel 右侧的整个区域。
    • 非常感谢您的 timr 和帮助。您固定了绘图的高度,但绘图宽度和选项卡集面板仍然没有覆盖侧边栏面板右侧的整个区域。请检查此链接中的结果dropbox.com/s/fquv5qtscfd3edq/1.png?dl=0
    • @aelwan 你试过mainPanel(width = 10, ...)吗?
    • 非常感谢。这正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 2018-05-29
    • 2017-12-28
    • 2018-06-21
    • 2017-06-04
    • 1970-01-01
    • 2019-12-01
    • 2021-02-14
    • 1970-01-01
    相关资源
    最近更新 更多