r - 在 Shiny App 中选择选项卡时打开 'modalDialog' 对话框

标签 r shiny modal-dialog

我创建了一个带有 navbarPage 的 Shiny 应用程序,它有 3 个选项卡,即 “A1”、“A2”和“A3”。现在我想在用户选择 'A2' 时创建一个模态对话框。下面是我的代码:

ui <- shinyUI(fluidPage(
    wellPanel(
          navbarPage(id = "AC", "AC :",
              tabPanel(tabName = "A1", h6("A1"), fluidRow()),
              tabPanel(tabName = "A2", h6("A2"), fluidRow()),
              tabPanel(tabName = "A3", h6("A3"), fluidRow())
            )
  )
))

server <- function(input, output, session) {


observe({
   if (input$AC == "A2")  {
     showModal(modalDialog(
        title = "Important message",
        div(id = "aa", style = "width: 1100px; height: 100px;", HTML("<b>This is </b>an important message!")),
        easyClose = TRUE
      ))
  }
  })
}

shinyApp(ui, server)

However, above App doesn't open a modal-dialogbox when 2nd Tab is selected.任何指向正确方法的指示都将受到高度赞赏。

谢谢,

最佳答案

您几乎已经做到了,AC 的输入是一个选项卡面板,使用 HTML 编码,所以 input$AC=="<h6>A2</h6>" , 不是 A2

observeEvent(input$AC, {
    print(input$AC)
    if (input$AC == "<h6>A2</h6>")  {
      showModal(modalDialog(
        title = "Important message",
        div(id = "aa", style = "width: 1100px; height: 100px;", HTML("<b>This is 
        </b>an important message!")),
        easyClose = TRUE
      ))
    }else{}

不要介意我使用 observeEvent()它只是为了调试目的

关于r - 在 Shiny App 中选择选项卡时打开 'modalDialog' 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52448973/

相关文章:

RSelenium 在 Linux 下通过 cron 运行时失败 - 为什么?

r - stringdist_join 结果为 NA

javascript - 使用 javascript 时从 Shiny 的应用程序下载绘图时出错

javascript - R Shiny : Check a Regular expression in textInput on UI

css - 在浏览器中默认缩小 Shiny 的应用程序

Android:如何获得模态对话框或类似的模态行为?

javascript - 当我关闭模态时,所有 hidden.bs.close 都被触发

r - 逐个单元格合并

forms - Lazarus - 子模态形式无响应

使用 bookdown 包引用 'hand-made' 表