【问题标题】:Shiny layout, is it possible to have a left and ride sidebarLayout in Shiny?Shiny 布局,Shiny 中是否可以有left andride sidebarLayout?
【发布时间】:2020-09-11 16:02:39
【问题描述】:

在 Shiny 中是否可以有这样的布局?

理想情况下,我想要一个左右侧边栏(我在shinydashboardPlus 中看到了一些解决方案,但这并不是我所追求的……)

我有一个与此示例结构类似的应用:

mychoices <- c("pick me A", 
               "pick me - a very long name here", 
               "no pick me - B", 
               "another one that is long")

ui <- 
  navbarPage(
    tabPanel("Dataset description",
    ),
    tabPanel("Data",
             sidebarLayout(
               sidebarPanel(
                 fluidRow(
                   column(2,
                          p(strong("Classes")),
                          actionButton(inputId = "selectall", label="Select/Deselect all",
                                       style='padding:12px; font-size:80%'),
                          br(), br(),
                          checkboxGroupButtons(
                            inputId = "classes",
                            choices = mychoices,
                            selected = mychoices,
                            direction = "vertical",
                            width = "100%",
                            size = "xs",
                            checkIcon = list(
                              yes = icon("ok", 
                                         lib = "glyphicon"))
                          ),
                   ),
                   column(6,
                          br()
                   ),
                   column(4,
                          p(strong("Controls")),
                          p("Transparency"),
                          sliderInput("trans", NULL,
                                      min = 0,  max = 1, value = .5),
                          actionButton("resetButton", "Zoom/reset plot", 
                                       style='padding:6px; font-size:80%'),
                          actionButton("clear", "Clear selection", 
                                       style='padding:6px; font-size:80%'),
                          actionButton("resetColours", "Reset colours", 
                                       style='padding:6px; font-size:80%'),
                   )
                 )
               ),
               mainPanel(
                 tabsetPanel(type = "tabs",
                             tabPanel("Scatter", id = "panel1",
                                      plotOutput(outputId = "scatter")),
                             tabPanel("PCA", id = "panel2"))
               )
             ))
  )


server <- function(input, output) {}

shinyApp(ui, server)

理想情况下,我想拆分sidebarLayout,以便一列在左侧(类),一列在右侧(控件),因为当应用加载时这两列是overlapping like this

请对更好的应用程序设计或解决方案有任何建议吗?

【问题讨论】:

  • 感谢@Waldi,但在我的帖子中已经提到我已经看过shinydashboardPlus 并且实际上有一个active post 寻求如何修复侧边栏以模仿上述内容。我希望有一个更简单更优雅的解决方案
  • 抱歉,我读得太快了……我这边没有其他解决方案。

标签: r shiny


【解决方案1】:

也许这就是你要找的。只是一个想法......所以我放弃了sidebarLayout 并添加了第二个sidebarPanel。为了确保侧边栏和主面板都放在一行中,我使用了width 参数。

library(shiny)
library(shinyWidgets)

mychoices <- c(
  "pick me A",
  "pick me - a very long name here",
  "no pick me - B",
  "another one that is long"
)

ui <-
  navbarPage(
    tabPanel("Dataset description", ),
    tabPanel(
      "Data",
      sidebarPanel(
        width = 3,
        p(strong("Classes")),
        actionButton(
          inputId = "selectall", label = "Select/Deselect all",
          style = "padding:12px; font-size:80%"
        ),
        br(), br(),
        checkboxGroupButtons(
          inputId = "classes",
          choices = mychoices,
          selected = mychoices,
          direction = "vertical",
          width = "100%",
          size = "xs",
          checkIcon = list(
            yes = icon("ok",
              lib = "glyphicon"
            )
          )
        )
      ),
      mainPanel(
        width = 6,
        tabsetPanel(
          type = "tabs",
          tabPanel("Scatter",
            id = "panel1",
            plotOutput(outputId = "scatter")
          ),
          tabPanel("PCA", id = "panel2")
        )
      ),
      sidebarPanel(
        width = 3,
        p(strong("Controls")),
        p("Transparency"),
        sliderInput("trans", NULL,
          min = 0, max = 1, value = .5
        ),
        actionButton("resetButton", "Zoom/reset plot",
          style = "padding:6px; font-size:80%"
        ),
        actionButton("clear", "Clear selection",
          style = "padding:6px; font-size:80%"
        ),
        actionButton("resetColours", "Reset colours",
          style = "padding:6px; font-size:80%"
        )
      )
    )
  )


server <- function(input, output) {}

shinyApp(ui, server)

【讨论】:

  • 这是个好主意!非常感谢!
猜你喜欢
  • 1970-01-01
  • 2019-12-02
  • 2020-04-19
  • 1970-01-01
  • 2019-03-24
  • 2014-09-14
  • 2015-10-05
  • 2020-11-30
  • 1970-01-01
相关资源
最近更新 更多