简体   繁体   中英

Shiny: How to increase the width of tabsetPanel to cover the whole area to the right of the sidebarPanel?

I want to create a shiny app in which there is a sidebarPanel and tabesetPanel.

I created the app using the code below

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)  

I want the tabsetPanel to cover the whole area to the right of the sidebarPanel.

As suggested in the answers of this question , I tried the following

div(, class ="span12") 

and

),  style='width: 1000px;)

However, still the tabset panel and the plots don't cover the whole area to right of the sidebarPanel.

Any suggestions how to do that?

Update

Thanks to @K. Rohde's answer, the plot now covers the whole height of the page next to the sidebarPanel but still doesn't cover the whole width

在此处输入图片说明

Edit: Sorry for not checking my first answer. But here is something that works:

For some reason, plotOutput is broken in the sense that height = "100%" does not work, otherwise that would be a solution. But you can add css3 by hand which scales your plot according to window size with ...vh .

Code:

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)  

I admit, it's more of a workaround.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM