Shinydashboard:使侧边栏在主体上打开而不是挤压主体

时间:2019-01-09 18:35:51

标签: javascript css r shiny shinydashboard

我不想让侧边栏打开并挤压身体,而是希望通过移过身体来打开侧边栏,这样就不会弄乱我的输出大小。
如果可能的话,我怎么能做到呢?

当前行为:

From

期望的行为:

To:

示例中使用的代码:

result

1 个答案:

答案 0 :(得分:0)

尝试使用此更新的代码,看看它是否满足您的需求。在我看来,至少在图表上打开侧边栏看起来不太好。为什么不在没有侧边栏的情况下打开您的应用?

    library(shinydashboard)
    library(shinyjs)

    ui <- dashboardPage(
   dashboardHeader(title = "Basic dashboard"),
 dashboardSidebar(
  sidebarMenu(
  menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
  menuItem("Widgets", tabName = "widgets", icon = icon("th"))
   )
 ),
 dashboardBody(
useShinyjs(),
tabItems(
  # First tab content
  tabItem(tabName = "dashboard",
          fluidRow(
            box(plotOutput("plot1", height = 250)),

            box(
              title = "Controls",
              sliderInput("slider", "Number of observations:", 1, 100, 50)
            )
          )
  ),

  # Second tab content
    tabItem(tabName = "widgets",
          h2("Widgets tab content")
  )
)
)
)

server <- function(input, output) {

 addClass(selector = "body", class = "sidebar-collapse")


 set.seed(122)
 histdata <- rnorm(500)

 output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}

shinyApp(ui, server)