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:
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.