本文介绍了闪亮:通过单击valueBox触发弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过单击valueBox在弹出窗口中显示数据表. valueBox本身应作为actionButton.

I want to display a table of data in a pop-up window by clicking on valueBox. The valueBox itself should work as an actionButton.

当我单击valueBox时,它将在弹出窗口中呈现一个表格,如下图所示.

When I click on the valueBox it should render a table in pop-up window as in the picture below.

任何人都可以提供有关此代码的帮助吗?

Can anyone help on this code?

我的代码:

library(shiny)
library(shinydashboard)

data <- iris

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

server <- function(input,output){
}

shinyApp(ui, server)

推荐答案

您可以使用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)

这篇关于闪亮:通过单击valueBox触发弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 19:19