【发布时间】:2019-06-26 20:18:09
【问题描述】:
当我使用 shinyjs::togglestate 将 UI 中的所有输入变量与 modalDialog 的输入变量进行比较时,它只适用于第一次。如果我关闭模态对话框并再次打开它,它就不起作用!
反应规则是:
if they are equal: button is blocked
if they are different: the button is enabled
Obs:模态对话框变量的值必须是在 UI 中选择的输入值。 (这是一个非常常见的例子,如果你有一个数据库检查并且你只是想更新它,如果有什么改变)
我创建了这个简单的应用程序来代表这个问题。 只需运行它,单击一次按钮,观察预期的行为,关闭模态对话框,第二次单击并观察它不再起作用,但是如果您更改模态对话框中的某些值,然后突然回到原始输入值“记得”再次工作。
library(shiny)
library(shinyjs)
shinyApp(
ui =
fluidPage(
useShinyjs(),
sidebarLayout(
sidebarPanel(
textInput("txt1","text"),
selectInput("select1","select",c("A","B","C")),
numericInput("n1","numeric",1),
dateInput("d1","date",value = Sys.Date()),
actionButton("go", "Go")),
mainPanel())
),
server =
function(input, output, session) {
observe({
shinyjs::toggleState("click", !(input$txt1 == input$txt2 &&
input$select1 == input$select2 &&
input$n1 == input$n2 &&
input$d1 == input$d2
) )
})
observeEvent(input$go,{
showModal(
modalDialog(
textInput("txt2", "text", input$txt1),
selectInput("select2", "select", c("A","B","C"), input$select1),
numericInput("n2", "numeric", input$n1 ),
dateInput("d2", "date", value = input$d1),
actionButton("click", "Click")
)
)
})
}
)
为什么会有这种意想不到的行为?有什么解决办法吗?
提前谢谢你!
【问题讨论】:
标签: r shiny modal-dialog shinyjs