accessing variables from code run above shinyUI()

I have code that I have placed before the shinyUI function in ui.R. This code reads in some data from a csv file, makes computations based on the column names, and places certain column names into two variables: orig_cols and clean_cols. The first is unprocessed col names, and the second is processed col names. Individually, this code works fine.

Later on, in my server.R file and within shinyServer(), I need to see if a string is in orig_cols. Here's the weird thing. Originally this worked fine. Later, when I worked on a copy of this code, R tells me that orig_cols is not found. I suspect that the problem was that orig_cols was stored in history, and if I clean out history, none of the code above shinyUI() is being called. In other words, a console check for exists("orig_cols")within shinyServer() returns FALSE.

I read online that code you want to be called once should come at the top. Since I am using a two-file structure (ui.R and server.R), in the past I have placed it at the top of the ui.R file (under library calls).

Why would this suddenly stop working? Is there a way to ensure that certain code gets called first? I have no way to really debug this, because if I put browser within shinyServer(), the UI is already presented, but if I put browser() in ui.R, the app just hangs.

Thanks in advance for any advice.

Shiny - Scoping rules for Shiny apps (rstudio.com)

perhaps use global.R

Thank you! global.R did the trick.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.