Включение анимации в insertUI - PullRequest
       12

Включение анимации в insertUI

0 голосов
/ 11 октября 2018

У меня есть следующий код как часть моего приложения:

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)

, который выскакивает новую кнопку (Descriptive, Trends или Rank) в ответ на ответ пользователя (нажав Inpatient, Emergencyили Амбулаторно).Мне бы хотелось, чтобы эти новые кнопки отображались с анимацией, например, доступных в пакетах shinyanimate или shinyjqui.Тем не менее, я сталкиваюсь с проблемой, когда jqui_add/jqui_remove/startAnim 1) требует, чтобы я уже создал пользовательский интерфейс заранее, и 2) не может позволить мне добавить объект в модальное окно, используя выборочный аргумент, который возможен в insertUI.Есть ли способ включить функции анимации в insertUI, который позволяет мне обойти эти проблемы?Спасибо!

1 Ответ

0 голосов
/ 07 июля 2019

Я знаю, что это старый вопрос, но я просто отвечаю, чтобы помочь любому, кто столкнется с этим в будущем.

Вы можете включить анимацию в insertUI, используя shinyanimate.

Отказ от ответственности: я являюсь автором пакетаIXanimate

Вот минимальныйпример из фрагмента кода, который вы предоставили выше:

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)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...