【问题标题】:shiny how to update value that store in the reactive?闪亮的如何更新存储在反应堆中的值?
【发布时间】:2015-07-19 03:03:20
【问题描述】:

我可以更新/更改保留在响应式中的值吗?例如,

x <- reactive({
  isolate(input$site1)
})

# Inpsect values from ui.R.
output$test <- renderText({

    # Take a dependency on input$goButton
    input$goPlot # Re-run when button is clicked

    site1 <- isolate(input$site1)

    if(site1 == x()){
        site1
    } else {

        paste(x(), site1)
        x() <- site1 // this not working obviously.
    }

})

有什么想法吗?

之所以要这样做,是因为我想在用户单击按钮input$goPlot 时存储先前的输入数据input$site1,并且我想确保用户再次单击按钮时选择不同的选项。如果他们选择相同的数据或不选择任何其他选项并单击按钮,那么我不希望应用程序执行任何操作。希望这是有道理的。

【问题讨论】:

  • 你能提供一些上下文吗?
  • 请看我的更新。谢谢。
  • 好吧,您的编辑很好地描述了反应性依赖关系。如果依赖没有改变,那么就没有理由改变输出。

标签: r shiny


【解决方案1】:

你想要的可能不是反应式表达,而是reactive values

shinyServer(function(input, output, session) {
     values <- reactiveValues(x="someValue")

     output$test <- renderText({
         ...
         if(site1 == isolate(values$x)) {
             ...
         } else {
             ...
             values$x <- site1 
         }
     })
})

【讨论】:

    猜你喜欢
    • 2019-01-10
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    • 2019-12-19
    • 2022-10-31
    • 2020-05-31
    • 1970-01-01
    • 2014-06-07
    相关资源
    最近更新 更多