且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

闪亮:通过单击valueBox触发弹出窗口

更新时间:2023-02-20 14:33:56

您可以使用shinyjs创建一个onclick事件.因此,您需要在ui中添加useShinyjs(),这可以通过将ui包装在tagList中来完成.

You can create an onclick event with shinyjs. Therefore you need to add useShinyjs() in your ui, which you can do by wrapping your ui in a tagList.

单击具有给定ID的元素时,将在您的服务器中触发onclick函数.因此,您还需要给valueBox一个ID.我决定将其包装在带有ID的div中.

The onclick function is triggered in your server when an element with a given ID is clicked. So you also need to give the valueBox an ID. I decided to wrap it in a div with an ID.

下一部分是每当触发onclick事件时创建一个弹出窗口.您可以使用shinyBS中的showModal函数来完成此操作.

Next part is to create a popup whenever the onclick event is triggered. You can do this by using the showModal function from shinyBS.

工作示例

library(shiny)
library(shinydashboard)
library(shinyjs)
library(shinyBS)

data <- iris

ui <- tagList(
  useShinyjs(),
  dashboardPage(
    dashboardHeader(title = "Telemedicine HP"),
    dashboardSidebar(),
    dashboardBody(
      fluidRow(
        div(id='clickdiv',
            valueBox(60, subtitle = tags$p("Attended", style = "font-size: 200%;"), icon = icon("trademark"), color = "purple", width = 4, href = NULL)
        )
      )
    )
  )
)

server <-  function(input, output, session){
  onclick('clickdiv', showModal(modalDialog(
    title = "Your title",
    renderDataTable(data)
  )))
}

shinyApp(ui, server)