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