我用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)
但是,当选择第二个选项卡时,在App上方,应用程序不会打开模态对话框。任何指向正确方法的指针都将受到高度赞赏。
谢谢
答案 0 :(得分:1)
您几乎拥有了,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()
只是出于调试目的