Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass data between functions in a Shiny app

Tags:

function

r

shiny

I have a shiny app where server.r including the following code

shinyServer(function(input, output) {

  data <- reactive(function() {
   # some processing
   df # dataframe with columns: name,date,count 
 })

  output$plot1 <- reactivePlot(function() {
   # boxplot based on df$count grouped by df$name
 })

 output$plot2 <- reactivePlot(function() {
   # linegraph based on x=df$date, y=df$count grouped by df$name
 })
})     

How do I construct it so that I can reference in the reactivePlots the df$count etc. I have created in the reactive function , 'data'

cheers

like image 215
pssguy Avatar asked Nov 27 '12 20:11

pssguy


1 Answers

Use data()$count. The () is how you retrieve a reactive function's value, and the fact that you can see data from within the two reactive plot functions is just a natural consequence of R's scoping rules.

like image 82
Joe Cheng Avatar answered Oct 01 '22 18:10

Joe Cheng