gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:30:22 25 4
gpt4 key购买 nike

我创建了一个带有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com