r语言 - 将动画合并到插入UI中



我的应用程序中有以下代码:

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)

它会弹出一个新按钮(描述性、趋势或排名(以响应用户响应(通过单击住院、急诊或门诊(。我希望这些新按钮与动画一起显示,例如shinyanimateshinyjqui包下可用的按钮。但是,我遇到了一个问题,jqui_add/jqui_remove/startAnim 1( 要求我已经事先创建了 UI,并且 2( 不允许我在模态窗口中使用在insertUI下可能的选择性参数添加对象。有没有办法将动画功能合并到insertUI中,让我绕过这些问题?谢谢!

我知道这是一个老问题,但只是回答,以便将来遇到这个问题的人有所帮助。

您可以使用shinyanimate将动画合并到insertUI中。

免责声明:我是Shinyanimate软件包的作者

下面是您上面提供的代码片段中的最小示例:

library(shinyBS)
library(shiny)
library(shinyanimate)
#ui----
ui = basicPage(
withAnim(),
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.")),
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
)
startAnim(session, 'Descriptivez', 'bounce')
# addPopover(session, "Descriptivez", "Descriptive Statistics", "Quote 1")
}) 
#Close Modal
observeEvent(input$ok, {
removeModal()
})
}
shinyApp(ui, server)

最新更新