I am trying to execute a function inside observeEvent()
I have
- two predefined functions:
calculate_value()andcreate_my_plot() - one input stored as reactive variable:
myreactive() - one dataset
aread from file. File is chosen according to input value. ais processed withcalculate_value()and passed tocreate_my_plot()
it goes like this:
myreactive<-reactive({input$myinput})
observeEvent(input$clicks,
{
filename<-paste(myreactive(),".csv")
a<-read.csv(filename)
x<-calculate_value(a,b=myreactive())
output$myplot<-renderPlot(
create_my_plot(x,myreactive())
})
Whenever I click action button this event is activated and new plot plotted. But also whenever myreactive() is changed this plot is replotted. This is good. But there is a problem with the replotted plot: it still uses "old" version of "x"
I need the function calculate_value() to be reacalculated whenever myreactive() is changed. It doesn't happen
I tried already usinig
x<-reactive({ calculate_value(a,b=myreactive()) })
but then nothing happens. Namely the function is not executed at all and x is left as null. For me this is unacceptable because "myreactive()" is changing the dataset and the description of the plot and if the plot is not re-plotted accordingly it is simply wrong.
It would be enough to delete the plot entirely if myreactive() changes but I actually would like to know what is going on and why I can't have calculate_value() re-do calculations each time while create_my_plot() can do it.
runGist(key). - Thomas K