-1

My shiny app relies on a main CSV dataframe from which users pick whatever variable they want to feed charts, maps, etc. I now want users to be able to create new variables by combining existing variables.

Problem: I need the new variables to be stored in that main CSV dataframe along all the other variables, and make them available just for the session, for every other control/map/chart. Of course I can't just append the new variable to my CSV dataframe because it's not a reactive object.

So I'm naturally thinking of turning the CSV dataframe into a reactive object on start.

I tried

  reactivedf<- reactiveVal()
  reactivedf(df)

But for some reason this approach doesn't work, in the sense that when the app starts, all the charts and maps are empty.

However, the reactive object does "wakes up" with a eventReactive statement that updates the reactivedf, and the maps and charts come to life:

reactivedf <- eventReactive(input$button, {

<code to create a new variable and append it to reactivedf>

}

How can I make the reactivedf fully available on start?

1 Answers1

0

Always a good idea to read the docs at least once.

reactivedf <- reactiveValues()
reactivedf$df <- df

It's good to give credit where credit is due. You didn't "naturally think" anything, you were put on this by a comment to your previous similar question.

Paul
  • 2,877
  • 1
  • 12
  • 28
  • I made it work using this structure however: `reactivedf <- reactiveVal(df)`,which works on app start. Then, inside every reactive or observe statement, I deploy the `reactivedf` (which is now able to be updated by the user) into a "static" `df` at the very beginning of each observe or reactive function like this: `df <- reactivedf()`. Regarding "naturally think", I was refering to the conceptual idea of turning a df into a reactive object. I opened a new thread to narrow down the formulation of the problem. Either way, I'm hereby posting the solution I found for future fellow readers. Thanks – Nahuel Patiño May 03 '19 at 03:21