1

我想创建一个Shiny应用程序,其中包含多个collapsible框作为一侧的菜单。为此,到目前为止,我已经使用了该bsCollapsePanel功能并将其放入sidebarPanel. 不幸的是,我从盒子到sidebarPanel. 盒子看起来已经启动了。但我只想使用可折叠的盒子作为侧边栏。

到目前为止,我使用了以下解决方案:

library(shinythemes)
library(shinyBS)

fluidPage(
  theme = shinytheme("cosmo"),
  titlePanel(# app title/description
    "ShinyApp"),
  sidebarLayout(
    mainPanel(plotOutput("plot1")),
    
    sidebarPanel(
      bsCollapsePanel(
        "Color Selection",
        actionButton("f1blue", "Blue"),
        actionButton("f1red", "Red"),
        actionButton("f2blue", "Blue"),
        actionButton("f2red", "Red"),
        style = "success"
      ),
      
     
    )
   
  )
)

这是图形输出: 在此处输入图像描述

这就是它应该的样子。我想避免这种“盒中盒”效应。侧边栏面板只有可折叠,没有边框和边距: 在此处输入图像描述

是否有解决方案和/或另一个包更适合创建可折叠/手风琴?

我很感激任何建议!

4

1 回答 1

0

这个怎么样:

library(shinythemes)
library(shinyBS)

ui <- fluidPage(
    theme = shinytheme("cosmo"),
    tags$style('#sidebar {border: none; background-color: transparent; padding: 0;}'),
    titlePanel(# app title/description
        "ShinyApp"),
    sidebarLayout(
        mainPanel(plotOutput("plot1")),
        sidebarPanel(
            id = "sidebar",
            bsCollapsePanel(
                "Color Selection",
                actionButton("f1blue", "Blue"),
                actionButton("f1red", "Red"),
                actionButton("f2blue", "Blue"),
                actionButton("f2red", "Red"),
                style = "success"
            ),
            bsCollapsePanel(
                "Color Selection",
                actionButton("f1blue", "Blue"),
                actionButton("f1red", "Red"),
                actionButton("f2blue", "Blue"),
                actionButton("f2red", "Red"),
                style = "success"
            )
        )
        
    )
)
server <- function(input, output, session) {
    output$plot1 <- renderPlot(plot(1))
}

shinyApp(ui = ui, server = server)

于 2021-07-20T23:27:17.613 回答