Are there global variables in R Shiny?

后端 未结 2 1538
我寻月下人不归
我寻月下人不归 2020-12-02 18:46

How do you declare global variables in with R Shiny so that you do not need to run the same pieces of code multiple times? As a very simple example I have 2 plots that use t

2条回答
  •  天涯浪人
    2020-12-02 19:01

    As mentioned in the link that @nico lists above, you can also use the <<- classifier inside your functions to make variables accessible outside of the function.

    foo <<- runif(10)
    

    instead of

    foo <- runif(10)
    

    The link says "If the objects change, then the changed objects will be visible in every user session. But note that you would need to use the <<- assignment operator to change bigDataSet, because the <- operator only assigns values in the local environment."

    I have used this to varying levels of success in shiny. As always, be careful with global variables.

提交回复
热议问题