【发布时间】:2015-08-13 10:07:12
【问题描述】:
我想在shiny 和shinydashboard 中使用reactiveValue、observe、observeEvent 框架,以便能够在单击时响应地更改信息框的颜色。
我还希望它在将鼠标悬停在 infoBox 上时在弹出框中显示带有一些文本的图像。
作为可复现示例的代码基础,请参阅this
但代码如下:
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Info boxes"),
dashboardSidebar(),
dashboardBody(
# infoBoxes with fill=FALSE
fluidRow(
# A static infoBox
infoBox("New Orders", 10 * 2, icon = icon("credit-card")),
# Dynamic infoBoxes
infoBoxOutput("progressBox"),
infoBoxOutput("approvalBox")
),
# infoBoxes with fill=TRUE
fluidRow(
infoBox("New Orders", 10 * 2, icon = icon("credit-card"), fill = TRUE),
infoBoxOutput("progressBox2"),
infoBoxOutput("approvalBox2")
),
fluidRow(
# Clicking this will increment the progress amount
box(width = 4, actionButton("count", "Increment progress"))
)
)
)
server <- function(input, output) {
output$progressBox <- renderInfoBox({
infoBox(
"Progress", paste0(25 + input$count, "%"), icon = icon("list"),
color = "purple"
)
})
output$approvalBox <- renderInfoBox({
infoBox(
"Approval", "80%", icon = icon("thumbs-up", lib = "glyphicon"),
color = "yellow"
)
})
# Same as above, but with fill=TRUE
output$progressBox2 <- renderInfoBox({
infoBox(
"Progress", paste0(25 + input$count, "%"), icon = icon("list"),
color = "purple", fill = TRUE
)
})
output$approvalBox2 <- renderInfoBox({
infoBox(
"Approval", "80%", icon = icon("thumbs-up", lib = "glyphicon"),
color = "yellow", fill = TRUE
)
})
}
shinyApp(ui, server)
这可能吗?
【问题讨论】:
-
嗨,h.l.m.当然有可能。最后,Shiny 正在生成 html,您可以根据需要添加尽可能多的 HTML / Javascript / JQuery / CSS。只要您不使用 Shiny Server 运行它,该服务器本身就要求很多,让您几乎空手而归。参见例如:stackoverflow.com/questions/23599268/… 或 chrisbeeley.net/?p=481,但要准备好深潜或坚持 SHINY 方式。
标签: javascript html r shiny