当input$some_selection
启动后发生变化时,只有第一个观察者会失效。这似乎是因为在启动时,反应值input_some_selection
被设置为NULL
并且不再更新。
按下单选按钮时,输出如下所示:
[1] "observed at point 1"
[1] "observed at point 2" # as expected until here
[1] "observed at point 1"
# why not invalidate the second observer also?
[1] "observed at point 1"
[1] "observed at point 1"
[1] "observed at point 1"
1)为什么会出现这种行为?是因为初始NULL
值吗?
2)我可以做些什么来使示例工作(使第二个观察者在input$some_selection
更改时无效,即生成依赖项)?
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(
radioButtons(inputId = "some_selection",
"Distribution type:",
c("Normal" = "norm",
"Uniform" = "unif",
"Log-normal" = "lnorm"))
)
)
)
server <- function(input, output, session) {
eventlog<-c("")
input_some_selection <- reactive({
input$some_selection
})
observeEvent(input$some_selection, {
print("observed at point 1")
eventlog<<-c(eventlog,"observed at point 1")
} )
observeEvent(input_some_selection, {
print("observed at point 2")
eventlog<<-c(eventlog,"observed at point 2")
} )
}
shinyApp(ui = ui, server = server)