【问题标题】:Start shiny with a hidden output that can be shown with toggle从可以通过切换显示的隐藏输出开始闪亮
【发布时间】:2022-01-16 10:10:03
【问题描述】:

我已经了解了如何创建一个可以隐藏然后显示闪亮输出的 actionButton。例如下面的代码,基于this link

dat <- data.frame(a=1:10, b=rexp(10, 1/10), c=letters[sample(1:24, 10)])

shinyApp(
  ui = fluidPage(
    useShinyjs(),
    actionButton("hide", "Toggle"),
    p("Text above plot"),
    plotOutput("plot"),
    p("Text below plot")
  ),
  server = function(input, output, session) {
    output$plot <- renderPlot({
      plot(b ~ a, data=dat)
    })

    observeEvent(input$hide, {
      toggle("plot") # if you want to alternate between hiding and showing
    })
  },
  options = list(height = 700)
)

情节开始显示,然后您可以单击“切换”按钮使其消失,然后再次出现。但是,我需要它开始隐藏,然后用户可以点击使其出现然后消失。

我怎样才能让它开始隐藏?谢谢!

【问题讨论】:

  • 试试hidden(plotOutput("plot"))
  • 服务器功能中的 hide("plot") 也可以使用。

标签: r shiny


【解决方案1】:

您可以toggle('plot') 在服务器内部但在反应式上下文外部,以便在应用启动时执行一次。例如:

    toggle('plot')
    
    observeEvent(input$hide, {
      toggle("plot") # if you want to alternate between hiding and showing
    })

【讨论】:

  • 完美!非常感谢!
猜你喜欢
  • 2015-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-05
  • 1970-01-01
  • 2019-06-12
  • 2022-01-22
相关资源
最近更新 更多