如果用户单击链接,如何显示模式对话框?

时间:2018-01-08 16:50:14

标签: shiny modal-dialog

如果用户点击链接,我想显示模态对话框。目前,如果用户单击操作按钮,模态对话框将起作用。

任何想法都表示赞赏。感谢。

## app.R ##

server <- function(input, output) {

  observeEvent(input$act_guide, {
    showModal(modalDialog(

      h5("Data Guidelines"),

      tags$ol(
      tags$li("Must have Resp_ID as the first column, occasion_ID as second and dependent variable as the third"), 
      tags$li("Must have no missing value in any fields")
      ), easyClose = TRUE, footer = NULL)
      )
    })
}

ui <- fluidPage(

  h4("Data guidelines"),
  br(),
  actionButton("act_guide", "Click Here!")
)

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:1)

您可以使用actionLink代替actionButton来触发弹出窗口,如下所示。

library(shiny)
library(shinyBS)

if(interactive()){
  shinyApp(
    ui <- fluidPage(
      h4("Data guidelines"),
      br(),
      actionLink(inputId = "link1", label = "Click Here!")
    ),

    server = function(input, output, session){

      observeEvent(input$link1, {
        showModal(modalDialog(
          h5("Data Guidelines"),
          tags$ol(
            tags$li("Must have Resp_ID as the first column, occasion_ID as second and dependent variable as the third"), 
            tags$li("Must have no missing value in any fields")
          ), easyClose = TRUE, footer = NULL)
        )
      })

    }
  )
}

另一种方法是在ui.R中使用bsModal来触发弹出窗口,如下所示:

library(shiny)
library(shinyBS)

if(interactive()){
  shinyApp(
    ui <- fluidPage(
      h4("Data guidelines"),
      br(),
      actionLink(inputId = "link1", label = "Click Here!"),

      bsModal(id = "modal1", title = "Test Modal", trigger = "link1",
              h5("Data Guidelines"),
              tags$ol(
                tags$li("Must have Resp_ID as the first column, occasion_ID as second and dependent variable as the third"),
                tags$li("Must have no missing value in any fields")
              ), easyClose = TRUE, footer = NULL)
    ),

    server = function(input, output, session){

    }
  )
}