【发布时间】:2018-10-20 19:12:08
【问题描述】:
这是我第一次使用 Shiny,如果这太简单了,请见谅。
我有一个名为 some_global_function() 的全局函数,只要按下名为 ok_input 的 actionButton 就会调用它。这将创建一个名为 algorithm_output 的局部变量。
现在,我希望能够在按下 另一个 actionButton (ok_means) 时访问该变量,但无需再次调用函数 some_global_function()。
有办法吗?代码是这样的:
server <- function(input, output) {
out_plots <- eventReactive(input$ok_input, {
#### I call the function here and this is the variable I want
#### to make global ########################################
algorithm_output = some_global_function(3, 2, 1)
do.call("grid.arrange", c(algorithm_output$indexes, nrow=3))
})
output$indexes <- renderPlot({
out_plots()
})
out_means <- eventReactive(input$ok_means, {
k = as.integer(input$k)
#### I want to access the variable here ################
matplot(algorithm_output$means[[k-1]], type = "l", lty=1)
########################################################
})
output$means <- renderPlot({
out_means()
})
}
【问题讨论】:
标签: r scope shiny global-variables local-variables