7

我正在构建一个Appwith Rshiny

我有几个,infoBox我想href在单击infoBox.

我使用 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)
4

3 回答 3

4

我决定改变方法。我现在在值框的 substile 元素中包含了一个 actionbutton(或 actionLink),并创建了一个链接到此 actionButton 的 bsModal 元素。
如果你不熟悉ShinyBS包,它允许在不包括 HTML 或 java 的情况下制作弹出框、工具提示等功能。

我遵循@Mikko Martila 的建议Shiny:将 addPopover 添加到 actionLink,这是一个可复制的示例,向您展示我的问题:

library("shiny")
library("shinydashboard")
library("shinyBS")

header <- dashboardHeader(title = "reporductible example")

body <- dashboardBody(valueBoxOutput("box_01"),
                      bsModal("modal", "foo", trigger = "", "bar"))
sidebar <- dashboardSidebar()
ui <- dashboardPage(header,sidebar,body,skin="green")
server = function(input, output, session) {
  # ----- First info box synthesis menu
  output$box_01 <- renderValueBox({
    entry_01 <- "BlaBla"
    valueBox(value=entry_01, icon = icon("users",lib="font-awesome"),
                    width=NULL,color = "blue",subtitle = HTML("<b>my substitle</b> <button id=\"button\" type=\"button\" class=\"btn btn-default action-button\">Show modal</button>")
    )
  })

  observeEvent(input$button, {
    toggleModal(session, "modal", "open")
  })
}

runApp(list(ui = ui, server = server))

我使用该HTML()选项在值框的副标题中添加我的按钮。

这不是我真正想要的,但它确实有效。

您可以通过使用这样的字幕来使用 actionLink (看起来更好):

subtitle=HTML("<b>my subtitle</b><a id=\"button_box_05\" href=\"#\" class=\"action-button\">
     <i class=\"fa fa-question-circle\"></i>

       </a>")
于 2015-12-29T10:31:09.163 回答
3

我遇到了同样的问题并且通过了这个链接,让它工作,没有添加一个单独的按钮,像这样。希望这会帮助那些希望解决类似问题的人

require(shiny)
require(shinydashboard)
require(shinyBS)


header <- dashboardHeader(title="ReproductibleExample")
sidebar <- dashboardSidebar(disable=T)
body <- dashboardBody(valueBoxOutput("box_01"),
                      textOutput("print"),bsModal("mod","title","btn"))

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)
  })
 observeEvent(input$button_box_01, {
  toggleModal(session,"mod","open")
  output$print<-renderText({
    print(input$button_box_01)
  })})
})

shinyApp(ui,server)
于 2017-12-02T10:12:32.650 回答
2

我只知道坏变种

1) 添加功能 tags$script(HTML("function clickFunction(link){ Shiny.onInputChange('linkClicked',link); }"))

2)编辑你的 valueBox 的 href 孩子

aa=valueBox(value="22", icon = icon("users","fa-lg",lib="font-awesome"),href="www", width=NULL,color = "light-blue",subtitle = "" ) aa$children[[1]]=a(href="#","onclick"=paste0("clickFunction('","click","'); return false;"),aa$children[[1]]$children)

3) observeEvent(input$linkClicked,{..})

于 2015-12-22T10:30:56.633 回答