Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

r - How can I pass data between functions in a Shiny app

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...