Shiny scoping in flexdashboard

I have a flexdashboard that uses shiny. Here's a MRE (just Rmd here). When I put the app live on shinyapps.io, I realized that one user's actions could affect other users. I understand that this is a scoping issue, but I'm confused about how scoping works in Flexdashboard.

This page explains scoping for 'regular' shiny apps:

You might want some objects to be visible across all sessions. For example, if you have large data structures, or if you have utility functions that are not reactive (ones that don’t involve the input or output objects), then you can create these objects once and share them across all user sessions (within the same R process), by placing them in app.R , but outside of the server function definition.

In Flexdashboard, there is no app.R file or server function. How does scoping work in these types of shiny apps?

1 Like

In shiny integration for flexdashboard, you have a special code chunk name that is global and act the global.R file in a two-file app. So the same as outside server function in an app.R

You'll find some example in the website example and in the loading data section because it is often for consuming loading time data that this is useful in a flexdashboard.

I'll see you use this chunk already, everything inside this chunk will be shared across all session. Is the object affected by user action in this part ? All the other chunks should be dedicated by session.

1 Like

Thanks, @cderv. Maybe the issue is that I used rv <- reactiveValues() in the global chunk.

Yes it is possible. Did you try to modified a little to see if the behavior changed ?

Yeah, moving rv <- reactiveValues() out of the global chunk did the trick.

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

1 Like