Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在Shining中隔离被动列表的元素?_R_Shiny_Reactive - Fatal编程技术网

R 如何在Shining中隔离被动列表的元素?

R 如何在Shining中隔离被动列表的元素?,r,shiny,reactive,R,Shiny,Reactive,假设我有下面的测试应用程序。我要寻找的是如何复制reactiveValues解决方案的功能。如果您使用该应用程序,您会发现隔离影响功能的方式有一个不同。使用被动值,我可以在被动列表中选择要隔离的元素 因此,如果用户单击按钮1,时间将始终改变。因此,时间将始终打印在observe中。如果用户单击同一按钮,由于数据没有改变,因此只显示时间。如果在按钮之间切换单击,将显示按钮名称和时间 您似乎无法使用reactive复制此功能。我的问题是我使用的真实场景reactivePoll。我的reactiveP

假设我有下面的测试应用程序。我要寻找的是如何复制
reactiveValues
解决方案的功能。如果您使用该应用程序,您会发现
隔离
影响功能的方式有一个不同。使用被动值,我可以在被动列表中选择要隔离的元素

因此,如果用户单击按钮1,时间将始终改变。因此,时间将始终打印在observe中。如果用户单击同一按钮,由于数据没有改变,因此只显示时间。如果在按钮之间切换单击,将显示按钮名称和时间

您似乎无法使用
reactive
复制此功能。我的问题是我使用的真实场景
reactivePoll
。我的reactivePoll返回一个列表
myData
。我想做的是,只有当myData$firstel发生变化时,才能
隔离
。但似乎从
myData
更新的任何反应性范式都将更新
myData$firstel
更改还是
myData$secondel
更改。有办法解决这个问题吗?我尝试将我的reactivePoll转换为reactiveValues,但似乎不起作用

library(shiny)

ui <- fluidPage(
  actionButton("button1","Button 1"),
  actionButton("button2","Button 2"),
  textOutput("output1"),
  textOutput("output2")
)

server <- function(input,output,session){

  myreactval <- reactiveValues(data = NULL, selection = NULL)

  observeEvent(input$button1,{
    myreactval$data <- Sys.time()
    myreactval$selection <- "button1"
  })
  observeEvent(input$button2,{
    myreactval$data <- Sys.time()
    myreactval$selection <- "button2"
  })


  myreact <- eventReactive(input$button1,{
    res <- list()
    res$data <- Sys.time()
    res$selection <- "button1"
    return(res)
  })


  output$output1 <- renderText({ myreact()$data })
  output$output2 <- renderText({ myreact()$selection })

  # REACTIVE SOLUTION
  # observe({
  #   print(myreact()$selection)
  # })
  # observe({
  #   print(isolate(myreact())$data)
  # })

  # REACTIVE VALUES SOLUTION
  observe({
    print(myreactval$selection)
  })
  observe({
    print(isolate(myreactval)$data)
  })
}

shinyApp(ui,server)
库(闪亮)

ui您可以使用以下代码段将反应列表
reacList
转换为反应值对象
reacVals

  reacVals <- reactiveValues()
  observe(
      purrr::imap(reacList(), function(val, name) {
        reacVals[[name]] <- val
      })
    )
reavals