如何调用observeEvent函数中的模块(闪亮)
我正在尝试在Shiny中设置一个简单的纸牌游戏,因此希望使用如何调用observeEvent函数中的模块(闪亮),r,shiny,shiny-reactivity,shinymodules,R,Shiny,Shiny Reactivity,Shinymodules,我正在尝试在Shiny中设置一个简单的纸牌游戏,因此希望使用 callModule(…)在observeEvent(input$..,{})的内部,因此我可以在发生不同事件时调用同一个模块。 不幸的是,这似乎不起作用 我知道,如果我在我的模块中简单地使用observeEvent(input$…,{}),代码确实可以工作,但是我必须为所有可能的事件定义类似的模型 playingUI <- function(id) { ns <- NS(id) tagList(# Create
callModule(…)
在observeEvent(input$..,{})
的内部,因此我可以在发生不同事件时调用同一个模块。
不幸的是,这似乎不起作用
我知道,如果我在我的模块中简单地使用observeEvent(input$…,{})
,代码确实可以工作,但是我必须为所有可能的事件定义类似的模型
playingUI <- function(id) {
ns <- NS(id)
tagList(# Create market and hand output
uiOutput(ns("market")),
uiOutput(ns("hand")),
# Actionbutton to take cards
actionButton(ns("take"),
label = "TAKE"))
}
player_server <- function(input, output, session, cards) {
# Pickerinput for Market
output$market <- renderUI(tagList(
pickerInput(
inputId = session$ns("market1"),
label = "Market",
choices = cards$market,
multiple = TRUE
),
# Pickerinput for Hand
pickerInput(
inputId = session$ns("Hand"),
label = "Hand",
choices = cards$hand,
multiple = TRUE
)
))
}
taking_server <- function(input, output, id, cards) {
cards$hand <- c(cards$hand, "new")
}
ui <- fluidPage(playingUI('game'))
server <- function(input, output, session) {
# Define playing cards
cards <- reactiveValues(
# Define market
market = c("Camel", "Gold", "Diamond"),
# Define hand
hand = c("Diamond", "Silver")
)
callModule(player_server, 'game', cards)
# Wrap the module 'taking_server' inside observe - does not work
observeEvent(input$take, {
callModule(taking_server, 'game', cards)
})
}
shinyApp(ui = ui, server = server)
playingUI这可能对您有帮助:这可能对您有帮助: