使用HREF信息框作为操作按钮 [英] Use href infobox as actionbutton

查看:13
本文介绍了使用HREF信息框作为操作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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 = "http://stackoverflow.com/"这样的外部网站,href选项可以很好地工作 但我不知道如何在应用程序的内部链接中进行链接。

编辑

我之所以进行此编辑,是因为我找到了一种解决方案,通过在valueBox输出列表中添加两个变量,使该框可单击,并使Slight认为它是一个操作按钮。
-类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)

推荐答案

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

我遵循@Mikko martla的建议Shiny: adding addPopover to 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>")

这篇关于使用HREF信息框作为操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆