Hide/show outputs Shiny R

前端 未结 3 1265
庸人自扰
庸人自扰 2020-12-11 05:21

I am trying to find out how to show and hide my outputs like graphics and tabels each time when the user change something in the widjets. For instance I have a slider input

3条回答
  •  眼角桃花
    2020-12-11 05:59

    The other answers here don't seem to provide the right/complete answer. The solution is actually quite simple.

    You need to use outputOptions(output, 'show', suspendWhenHidden = FALSE)

    Below is a sample code that displays the text inside a conditionalPanel if the dropdown selection is 2 and hides if it is 1.

      library(shiny)
      
      ui <- fluidPage(
        selectInput("num", "Choose a number", 1:2),
        
        conditionalPanel(
          condition = "output.show",
          "The selected number is 2 so this text is displayed. Change it back to 1 to hide."
        )
        
      )
      
      server <- function(input, output, session) {
        output$show <- reactive({
              input$num == 2 # Add whatever condition you want here. Must return TRUE or FALSE
          })
        
        outputOptions(output, 'show', suspendWhenHidden = FALSE)
      }
        
      shinyApp(ui = ui, server = server)
    

提交回复
热议问题