【发布时间】:2016-03-28 13:23:27
【问题描述】:
我正在用Rshiny 构建一个App。
我有几个infoBox,我想在单击infoBox 时使用href 选项弹出一个窗口。
我使用 shinyBS 作为弹出选项。 这是我尝试过的:
valueBox(value=entry_01, icon = icon("users","fa-lg",lib="font-awesome"),href=shinyInput(actionLink,id='button_01',len=1,class="btn btn-default action-button",label=""),
width=NULL,color = "light-blue",subtitle = ""
)
但我发现href 选项可以完美地工作,如果我们想链接到外部网站,比如href = "http://stackoverflow.com/"
但我不知道如何链接到应用程序的内部链接。
编辑
我进行此编辑是因为我找到了一个解决方案,通过在 valueBox 输出列表中添加两个变量,使框可点击并使闪亮认为它是一个操作按钮。
- 班级action-button
- id 允许我们使用观察或观察事件来检测何时单击值框。
这是一个可复制的例子
require(shiny)
require(shinydashboard)
header <- dashboardHeader(title="ReproductibleExample")
sidebar <- dashboardSidebar(disable=T)
body <- dashboardBody(valueBoxOutput("box_01"),
textOutput("print"))
ui <- dashboardPage(header, sidebar, body)
server<-shinyServer(function(input, output,session) {
output$box_01 <- renderValueBox({
entry_01<-20
box1<-valueBox(value=entry_01
,icon = icon("users",lib="font-awesome")
,width=NULL
,color = "blue"
,href="#"
,subtitle=HTML("<b>Test click on valueBox</b>")
)
box1$children[[1]]$attribs$class<-"action-button"
box1$children[[1]]$attribs$id<-"button_box_01"
return(box1)
})
output$print<-renderText({
print(input$button_box_01)
})
})
shinyApp(ui,server)
【问题讨论】:
标签: r shiny infobox shinydashboard action-button