0
votes

So I have a shiny app that is a navbarPage, and I want to create a sidebar navigation menu inside only one of the pages.

I have two columns, each with text and input/action/download buttons, and what I aiming at is to have two buttons on the sidebar which get as output one of my two columns.

Basically, currently they appear at the same time, side by side, and I want them to appear one at a time, by clicking one of two sidebar tab buttons.

I'm really sorry if I'm being confusing, I'm doing my best

Here is my tabPanel with the two columns:

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')))
)
)

I suspect I might need to use something like tabsetPanel, or on the other hand just move around with sidebarPanel and mainPanel, but I'm pretty lost and wondering if someone has any idea how to do this

Thanks in advance for any answers

1
Please, post all required libraries, ui and server side of the program.Sada93

1 Answers

1
votes

Not sure this covers your case completely (a drawing of the desired layout would have been very helpful), but here is an app with a sidebar layout in one tab and dynamic show/hide for contents in two columns. Note that it uses shinyWidgets::checkboxGroupButtons instead of regular actionButton or actionBttn.

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