简体   繁体   中英

How to specify the width of a sidebarPanel in pixels?

How to specify the width of a sidebarPanel in pixels? The width argument is not accurate enough in my case.

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(width = 5), # This is not accurate enough!
    mainPanel()))

server <- function(input, output, session) {}

shinyApp(ui, server)

You can also specify the width as a function of the percentage, 100% = full width instead of hard-coding it to px

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    div(style="width: 70%;",sidebarPanel(width = 5)), # This is not accurate enough!
    mainPanel()))

server <- function(input, output, session) {}

shinyApp(ui, server)

With the help of R shiny - background of sidebar panel I found the following solution:

library(shiny)

ui <- fluidPage(
  tags$head(tags$style(HTML('#sidebar {width: 100px;}'))),
  sidebarLayout(
    sidebarPanel(id = "sidebar"),
    mainPanel()))

server <- function(input, output, session) {}

shinyApp(ui, server)

This one does not affect other wellPanels .

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