【发布时间】:2021-08-31 11:02:13
【问题描述】:
我编写了一个显示模式对话框的小模块。用户使用对话框选择值,然后单击按钮进行确认。然后将这些值传递给首先调用该模块的应用程序。
当我第一次运行模块时,它会按需要完成。我第二次运行它时,模块内的确认按钮会自动被点击(同样,选择的值也会被重置)。 当我第三次运行该模块时,它会按需要完成。第四次,奇怪的行为仍在继续。以此类推。
下面的最小reprex。
应用程序:
library(shiny)
source("condSelectModule2.R")
ui <- fluidPage(
condSelectUI("chooseCond"),
actionButton("makeChoice", "Choose"),
textOutput("showCond")
)
server <- function(input, output, session) {
observeEvent(input$makeChoice, {
r <- condSelectServer("chooseCond", c(1,2,3))
output$showCond <- renderText(unlist(r()))
})
}
shinyApp(ui, server)
模块:
condSelectUI <- function(id) {}
condSelectServer <- function(id, conds)
moduleServer(id, function(input, output, session) {
ns <- session$ns
showModal(modalDialog(
title="Select a number",
footer=tagList( fluidRow(
selectInput(ns("Number"), "Select a number", choices=conds)
),
actionButton(ns("goBtn"), "Ok")
)))
observeEvent(input$goBtn, {
print(c(input$Number))
removeModal()
}
)
# return value
reactive(input$Number)
})
【问题讨论】:
-
我的感觉是我调用模块的方式有缺陷。
-
condSelectUI在哪里? -
@PorkChop 已添加,谢谢。这是一个空函数。
标签: r shiny shiny-reactivity