Использование Popover (блестки) в функции InsertUI - PullRequest
0 голосов
/ 04 октября 2018

У меня проблемы с использованием функции popover в моем приложении Shiny, когда я использую insertUI.См. Мой код ниже.

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)

С этим кодом мой начальный вывод в модальное окно с кнопками уровня 0 (стационарный, неотложный и амбулаторный) успешно отображает всплывающее окно.Однако кнопки уровня 1 (описательная статистика, тренды и рейтинг), которые создаются в ответ на кнопки уровня 0, не отображают всплывающие окна.Я просмотрел документацию bsbutton безуспешно.Что мне делать?

1 Ответ

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

В фоновом режиме происходит несколько интересных вещей из JavaScript и веб-браузера.Я получил решение работать с использованием 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)
...