0
我想知道如何访问一个模块中的反应函数到另一个模块。如果模块中有多个反应功能,我可以在另一个模块中访问它们吗?如何在另一个闪光模块(从一个模块到另一个模块的反应函数)中调用闪亮模块
所以基本上我怎么会叫/传递一个闪亮的模块的反应函数到另一个闪亮的模块(反应从一个模块到另一个功能) 感谢
module1Ui <- function(id) {
ns <- NS(id)
wellPanel(
selectInput(
ns('cars'), "cars:", list("Select" = "", "a" = "mazda", "b" = "ford"))
) }
module1<-function(input, output, session){
dataone = reactive({
if(input$cars=="mazda"){ mtcars$mpg}
else(mtcars$hp)
})
}
module2<-function(input, output, session){
dataone()
#here I want dataone from the above module1
# I tried to use callmodule(module1,_) but then didnt understand what the id would be in this case?
}
library(shiny)
ui <- fluidPage( sliderInput("slider","how much cars?", 1, 10, 1, width = "100%"),
uiOutput("selectors"),
verbatimTextOutput("datap")
)
server <- function(input, output, session){
for(i in 1:10)
callModule(module1, i)
output$selectors <- renderUI({
lapply(1:input$slider, module1Ui)
})
#below code just to test if I was able to correctly get dataone() #from module2
output$datap<-renderPrint(
lapply(1:input$slider, function(i){ datas<-callModule(module2,i)
datas()})
)
}
shinyApp(ui, server)
感谢
感谢您的答复,但我仍然无法使用dataone()的模块2。假设我想使用dataone()在module2中执行一些计算。例如。 abc <-dataone()$ var1 – shamary
您需要在被动环境中使用它。更新我的代码。 – shosaco