簡體   English   中英

在InsertUI函數中使用Popover(shinybs)

[英]Utilizing Popover (shinybs) within InsertUI function

當我使用insertUI時,我在我的Shiny應用程序中使用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 bsbuttons(Inpatient,Emergency和Ambulatory)的模態窗口的初始輸出成功顯示了彈出窗口。 但是,響應Level0按鈕而被動反應創建的Level1按鈕(Descriptive Statistics,T​​rends和Rank)不會顯示任何彈出窗口。 我查看了bsbutton文檔但沒有成功。 我該怎么辦?

在后台有一些很酷的javascript / web瀏覽器。 我有一個使用addPopover工作的解決方案,同時將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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM