简体   繁体   English

将动画纳入insertUI

[英]Incorporating Animation into insertUI

I have the following code as part of my app: 我的应用中包含以下代码:

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)

which pops up a new button (either Descriptive, Trends, or Rank) in response to the user response (by clicking Inpatient, Emergency, or Ambulatory). 它会根据用户的响应(通过单击“住院”,“紧急情况”或“非住院”)弹出一个新按钮(“描述性”,“趋势”或“排名”)。 I would like these new buttons to appear with an animation, such as those available under the shinyanimate or shinyjqui packages. 我希望这些新按钮与动画一起显示,例如shinyanimateshinyjqui软件包下的shinyanimate shinyjqui However, I'm running into the problem where jqui_add/jqui_remove/startAnim 1 ) requires that I already have created the UI beforehand and 2) cannot allow me to add an object in the modal window using the selective argument that is possible under insertUI . 但是,我jqui_add/jqui_remove/startAnim 1了一个问题,其中jqui_add/jqui_remove/startAnim 1 )要求我已经预先创建了UI,并且2)不允许我使用insertUI下可能的选择参数在模态窗口中添加对象。 Is there a way to incorporate the animation features into insertUI that allows me to bypass these issues? 有没有一种方法可以将动画功能合并到insertUI ,从而使我能够绕过这些问题? Thank you! 谢谢!

I know this is an old question but just answering so that it would help anyone who stumble across this in future. 我知道这是一个古老的问题,但只需回答即可,以便将来对任何偶然发现此问题的人有所帮助。

You can incorporate Animation into insertUI using shinyanimate . 您可以使用shinyanimate将Animation合并到insertUI中。

Disclaimer: I am the author of shinyanimate package 免责声明:我是Shinyanimate软件包的作者

Here is a minimal example from the code snippet you provided above: 这是您上面提供的代码段中的一个最小示例:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM