问题描述
我想通过单击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触发弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!