如何在闪亮的navbarPage中的单个tabPanel内创建侧边栏导航菜单?

时间:2019-08-31 18:47:56

标签: r shiny

所以我有一个闪亮的应用程序,它是navbarPage,我想只在其中一个页面内创建侧边栏导航菜单。

我有两列,每列都有文本和输入/操作/下载按钮,而我的目标是在侧边栏上有两个按钮,它们分别作为我两列的输出。

目前,基本上,它们可以同时并排显示,我希望通过单击两个侧边栏选项卡按钮之一,使它们一次显示一次。

如果我感到困惑,我会尽力而为,我真的很抱歉

这是我的带有两列的tabPanel:

navbarPage(
tabPanel(title="Download two different tsv files",

######## FIRST COLUMN IN MY tabPanel

fluidRow(
    column(6,align="center", tags$strong("Download tsv file number one"),
                     textInput(inputId="input1",tags$strong("Enter the name of the set of data you want to download"),placeholder="Example: something"),
                   downloadBttn("downloadData","Download tsv 1")
)),

####### SECOND COLUMN
fluidRow(
column(6,align="center", tags$strong("Download tsv file number two"),
                                          downloadBttn('downloadData2','Download tsv 2')))
)
)

我怀疑我可能需要使用tabsetPanel之类的东西,或者另一方面,只需要使用sidebarPanel和mainPanel来移动,但是我很迷茫,想知道是否有人知道如何做

预先感谢您的回答

1 个答案:

答案 0 :(得分:1)

不确定这是否能完全涵盖您的情况(所需布局的图纸将非常有帮助),但这是一个应用程序,其中一个选项卡中具有侧边栏布局,动态显示/隐藏两列内容。请注意,它使用shinyWidgets::checkboxGroupButtons而不是常规的actionButtonactionBttn

library(shiny)
library(shinyWidgets)

ui <-
  navbarPage(title = "T I T L E",
    tabPanel(title = "Download two different tsv files",
                      sidebarLayout(
                        sidebarPanel(
                          width = 2,
                          checkboxGroupButtons(inputId = "show", 
                                               label = "Show column:", 
                                               choices = c("Column 1", "Column 2"))
                        ),
                      mainPanel(
                          fluidRow(
                          column(6,
                                 uiOutput("col1")),
                          column(6,
                                 uiOutput("col2"))
                        )
                        )
                      )
    ),
    tabPanel(title = "Tab 2")

    )


server <- function(input, output, session) {
  col1 <- reactive({
    if ("Column 1" %in% input$show) {
      x <- tagList(
      h4("Stuff for first column"),
      actionButton('btn1', 'Button for column 1')
      )
    } else {
      x <- div()
    }
    x
  })

  output$col1 <- renderUI({
    col1()
  })

  col2 <- reactive({
    if ("Column 2" %in% input$show) {
      x <- tagList(
      h4("Stuff for second column"),
      actionButton('btn2', 'Button for column 2')
      )
    } else {
      x <- div()
    }
    x
  })

  output$col2 <- renderUI({
    col2()
  })

}

shinyApp(ui, server)

enter image description here

相关问题