我想知道是否可以使用闪亮(和闪亮BS)创建一个交互式弹出对话框。
例如,我有一个字符串,我想更改它,在执行之前会出现一个对话框,询问我是否真的要更改它。如果我说“是”,它会这样做,否则它会丢弃更改。这是我的尝试,但我发现了两个问题:1.如果单击“是”或“否”,则没有任何变化 2.您始终需要关闭底部的“关闭”框。
rm(list = ls())
library(shiny)
library(shinyBS)
name <- "myname"
ui =fluidPage(
textOutput("curName"),
br(),
textInput("newName", "Name of variable:", name),
br(),
actionButton("BUTnew", "Change"),
bsModal("modalnew", "Change name", "BUTnew", size = "small",
textOutput("textnew"),
actionButton("BUTyes", "Yes"),
actionButton("BUTno", "No")
)
)
server = function(input, output, session) {
output$curName <- renderText({paste0("Current name: ", name)})
observeEvent(input$BUTnew, {
output$textnew <- renderText({paste0("Do you want to change the name?")})
})
observeEvent(input$BUTyes, {
name <- input$newName
})
}
runApp(list(ui = ui, server = server))
其他建议非常受欢迎!!