【问题标题】:Making dynamic wellPanels in shiny使动态wellPanels闪亮
【发布时间】:2019-10-26 19:39:14
【问题描述】:

我一直在寻找并尝试使 wellPanel 具有闪亮的动态,但没有任何乐趣。动态我的意思是它们应该只在它们将包含的对象被创建而不是之前出现。

下面是一些可重现的代码来说明问题。您会看到,即使在显示任何绘图之前,wellPanel 和标题也已显示。这里的标题只是一个 helpText,我可以使这个反应,但不是 wellPanel。老实说,这不会影响应用程序的功能,但它并不漂亮,让我发疯。

library(shiny)

ui<- shinyUI(fluidPage(
  titlePanel("My example shiny"),
  fluidRow(
    column(3, wellPanel(
      numericInput("n", "N:", min = 0, max = 100, value = 50),
       actionButton("goButton", "Go!")  

    )),

    column(6,

           wellPanel(
           plotOutput("plot1", width = 400, height = 300),
           helpText("Caption: This text should appear at the same time as the plot and well"),
           #verbatimTextOutput("text")
           )
    )
  )
)
)


server <- function(input, output) {

  plot1 <- eventReactive(input$goButton, {
     hist(rnorm(input$n))   

    })


   output$plot1 <- renderPlot({
     plot1()

      })

}

shinyApp(ui = ui, server = server)

该应用程序将有多个 wellPanel,最好不要让初始显示充满空面板,否则会让人觉得有些地方不对劲。

任何指针都将受到高度赞赏。 干杯

【问题讨论】:

    标签: r shiny reactive


    【解决方案1】:

    使用conditionalPanel 是否适合您?

    library(shiny)
    
    ui<- shinyUI(fluidPage(
      titlePanel("My example shiny"),
      fluidRow(
        column(3, wellPanel(
          numericInput("n", "N:", min = 0, max = 100, value = 50),
          actionButton("goButton", "Go!")  
        )),
        column(6,
               conditionalPanel("output.hide_panel",
                  wellPanel(
                    plotOutput("plot1", width = 400, height = 300),
                    helpText("Caption: This text should appear at the same time as the plot and well")
                  )
               )
        )
      )
    ))
    
    server <- function(input, output) {
    
      output$hide_panel <- eventReactive(input$goButton, TRUE, ignoreInit = TRUE)
      outputOptions(output, "hide_panel", suspendWhenHidden = FALSE)
    
      plot1 <- eventReactive(input$goButton, {
        hist(rnorm(input$n))   
      })
    
      output$plot1 <- renderPlot({
        plot1()
      })
    
    }
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 感谢您的帮助,它完美地完成了这项工作。我以前没有遇到过条件面板,我很惊讶它没有出现在我的网络搜索中。再次感谢您。干杯
    猜你喜欢
    • 2018-12-22
    • 2015-01-15
    • 2014-04-21
    • 2017-04-28
    • 2018-01-09
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    相关资源
    最近更新 更多