Shiny in R: How can I fade-out my plotOutput from renderPlot if certain conditions are not met?

后端 未结 2 2131
盖世英雄少女心
盖世英雄少女心 2021-01-16 07:49

the question is straight forward. First, I tried an if-else condition within the render plot. Something like

if (input$Next > 0) {
   plot(...)
}
else {
          


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-16 08:09

    Use a conditional panel like so:

    library(shiny)
    ui =fluidPage(
      sidebarPanel(
        conditionalPanel(condition="input.Next>0",
        plotOutput("test")),
        actionButton("Next", "Next")
      ))
    
    server=shinyServer(function(input, output, session) {
    
        output$test <- renderPlot({
    
            req(input$Next > 0)
    
          pt <- plot(input$Next,2)
          print(pt)
        })
    
    })
    
    shinyApp(ui=ui,server=server)
    

提交回复
热议问题