Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
786 views
in Technique[技术] by (71.8m points)

r - Use href infobox as actionbutton

I was building an App with Rshiny.

I have a couple of infoBoxand I would like to use the href option to make a pop-up when clicking on the infoBox.

I use shinyBS for the popup options. here is what i tried :

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 = ""
)

But I figured out that the href option work perfectly if we want to link on an external web site like href = "http://stackoverflow.com/" but I didn't know how to link in an internal link of the app.

EDIT

I make this edit because i found a solution which make the box clickable and make shiny think it was an action button, by adding two variable inside the valueBox output list.
- the class action-button
- The id which allow us to use observe or observeEvent to detect when the valuebox is clicked.

Here is a reproductible example

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I decided to change the method. I have now include an actionbutton (or actionLink) inside the substile element of the value box and create a bsModal element linked to this actionButton.
If you are not familiar with the ShinyBS package it allow to make popover, tooltip etc features without including HTML or java.

I follow the @Mikko Martila advice Shiny: adding addPopover to actionLink and here is a reproductile example to show you my issue :

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))

I use the HTML() option to add my button inside the subtitle of value boxes.

It's not really what i wanted but it do the work.

You can do it with actionLink (it's look better) by using subtitle like this :

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

       </a>")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...