当我使用insertUI时,我在我闪亮的应用程序中使用popover功能有问题。请看下面的代码。
library(shinyBS)
library(shiny)
#ui----
ui = basicPage(
actionButton("show", "Create a New Analysis")
)
#server----
server = function(input, output, session) {
#Show modal when button is clicked.
observeEvent(input$show, {
showModal(dataModal())
})
#dataModal----
#The main modal dialog function. Sets the initial buttons shown on the dialog.
dataModal <- function() {
modalDialog(
h2("Analysis Setup", align = "center"),
h4("Choose a Setting of Care:", align = "center"),
#Level0----
#Inpatient button. The HTML function (i.e. div, style) is used to evenly space
#the buttons in the dialog window.
div(style="display:inline-block;width:32%;text-align: center;",
popify(actionButton("Inpatientz", "Inpatient", icon("user-md")),
"Inpatient",
"Dialogue 1.")),
#Emergency button. The HTML function (i.e. div, style) is used to evenly space
#the buttons in the dialog window.
div(style="display:inline-block;width:32%;text-align: center;",
popify(bsButton("Emergencyz", HTML("Emergency <br> Department"), icon("ambulance"), style = "default", size = "default"),
"Emergency",
"Dialogue 2.")),
#Ambulatory button. The HTML function (i.e. div, style) is used to evenly space
#the buttons in the dialog window.
div(style="display:inline-block;width:32%;text-align: center;",
popify(bsButton("Ambulatoryz", HTML("Ambulatory <br> Surgery"), icon("medkit"), style = "default", size = "default"),
"Ambulatory",
"Dialogue 3.")),
tags$div(id = 'placeholder'),
footer = tagList(
modalButton("Cancel"),
actionButton("ok", "OK")
),
#easyClose is an argument which allows the user to click outside the
#dialog window or press the escape key to close the dialog window.
easyClose = TRUE
)
}
#Level1----
observeEvent(input$Inpatientz, {
#Adds Descriptive Statistics button with popover.
insertUI(selector = '#placeholder',
ui = popify(bsButton("Descriptivez", "Descriptive Statistics", style = "default", size = "default"),
"Descriptive Statistics", "Quote 1"))
})
observeEvent(input$Emergencyz, {
#Adds Trends button with popover.
insertUI(selector = '#placeholder',
ui = popify(bsButton("Trendsz", "Trends", style = "default", size = "default"),
"Trends", "Quote 2"))
})
observeEvent(input$Ambulatoryz, {
#Adds Rank button with popover.
insertUI(selector = '#placeholder',
ui = popify(bsButton("Rankz", "Rank", style = "default", size = "default"),
"Rank", "Quote 3"))
})
#Close Modal
observeEvent(input$ok, {
removeModal()
})
}
shinyApp(ui, server)使用此代码,我的初始输出到带有Level0按钮(住院、紧急情况和动态)的模态窗口成功地显示了弹出窗口。但是,响应于Level1按钮而创建的Level0按钮(描述性统计、趋势和排名)不显示任何弹出窗口。我查看了bsbutton文档,但没有成功。我该怎么办?
发布于 2018-10-05 02:22:25
后台有一些很酷的javascript/web浏览器内容。我找到了一个使用addPopover的解决方案,同时将immediate = TRUE添加到insertUI函数(https://shiny.rstudio.com/reference/shiny/1.0.0/insertUI.html),并删除popify函数(不再需要)。
我的代码如下:
library(shinyBS)
library(shiny)
#ui----
ui = basicPage(
actionButton("show", "Create a New Analysis")
)
#server----
server = function(input, output, session) {
#Show modal when button is clicked.
observeEvent(input$show, {
showModal(dataModal())
})
#dataModal----
#The main modal dialog function. Sets the initial buttons shown on the dialog.
dataModal <- function() {
modalDialog(
h2("Analysis Setup", align = "center"),
h4("Choose a Setting of Care:", align = "center"),
#Level0----
#Inpatient button. The HTML function (i.e. div, style) is used to evenly space
#the buttons in the dialog window.
div(style="display:inline-block;width:32%;text-align: center;",
popify(actionButton("Inpatientz", "Inpatient", icon("user-md")),
"Inpatient",
"Dialogue 1.")),
#Emergency button. The HTML function (i.e. div, style) is used to evenly space
#the buttons in the dialog window.
div(style="display:inline-block;width:32%;text-align: center;",
popify(bsButton("Emergencyz", HTML("Emergency <br> Department"), icon("ambulance"), style = "default", size = "default"),
"Emergency",
"Dialogue 2.")),
#Ambulatory button. The HTML function (i.e. div, style) is used to evenly space
#the buttons in the dialog window.
div(style="display:inline-block;width:32%;text-align: center;",
popify(bsButton("Ambulatoryz", HTML("Ambulatory <br> Surgery"), icon("medkit"), style = "default", size = "default"),
"Ambulatory",
"Dialogue 3.")),
tags$div(id = 'placeholder'),
footer = tagList(
modalButton("Cancel"),
actionButton("ok", "OK")
),
#easyClose is an argument which allows the user to click outside the
#dialog window or press the escape key to close the dialog window.
easyClose = TRUE
)
}
#Level1----
observeEvent(input$Inpatientz, {
#Adds Descriptive Statistics button with popover.
insertUI(selector = '#placeholder',
ui = bsButton("Descriptivez", "Descriptive Statistics", style = "default", size = "default"), immediate = TRUE
)
addPopover(session, "Descriptivez", "Descriptive Statistics", "Quote 1")
})
observeEvent(input$Emergencyz, {
#Adds Trends button with popover.
insertUI(selector = '#placeholder',
ui = bsButton("Trendsz", "Trends", style = "default", size = "default")
, immediate = TRUE)
addPopover(session, "Trendsz", "Trends", "Quote 2")
})
observeEvent(input$Ambulatoryz, {
#Adds Rank button with popover.
insertUI(selector = '#placeholder',
ui = bsButton("Rankz", "Rank", style = "default", size = "default"), immediate = TRUE)
addPopover(session, "Rankz", "Rank", "Quote 3")
})
#Close Modal
observeEvent(input$ok, {
removeModal()
})
}
shinyApp(ui, server)https://stackoverflow.com/questions/52651525
复制相似问题