我如何在Shiny应用程序中的函数之间传递数据 [英] How can I pass data between functions in a Shiny app
本文介绍了我如何在Shiny应用程序中的函数之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 by df $ name
})
output $ plot2< --activePlot(function(){
#linegraph基于x = df $ date,y = df $ count由df $ name $ b $}}
})
我如何构建它,以便可以在reactivePlots中引用df $ count等我在反应函数中创建的' data
欢呼
解决方案使用
数据()$计数
。 ()
是您如何检索一个被动函数的值,以及您可以在两个函数内看到 data
的事实反应性情节功能只是R的范围规则的自然结果。 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
解决方案
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.
这篇关于我如何在Shiny应用程序中的函数之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文