【发布时间】:2021-11-23 05:27:34
【问题描述】:
我有一个闪亮的应用程序,带有一个按钮,它调用一个模式对话框,应该在其中插入 UI。我正在使用insertUI,因为我想动态添加 UI 元素。问题是,每当我按下操作按钮时,应用程序就会崩溃并显示以下错误消息:
Warning: Error in as.character: cannot coerce type 'closure' to vector of type 'character'
[No stack trace available]
如果我在insertUI() 中设置immediate = T 则没有错误,也没有插入UI。有人可以解释这里发生了什么吗?这是一个代表。
library(shiny)
ui <- fluidPage(
actionButton("add", "addConstraints")
)
server <- function(input, output, session) {
observeEvent(input$add, {
showModal(modalDialog(
selectizeInput(session$ns("constraintType"), label = "Select constraint type", choices = c("Comparison", "Numeric", "Interval")),
tags$div(id = session$ns("constraintPlaceholder")),
insertUI(
selector = paste0("#", session$ns("constraintPlaceholder")),
where = "afterEnd",
ui = HTML("test")
),
title = "Set Constraints",
footer = tagList(
modalButton("Cancel"),
actionButton(session$ns("confirmConstraint"), "Add")
)
))
})
}
shinyApp(ui, server)
【问题讨论】: