Use href info box as actionbutton

I built the App with Rshiny .

I have a infoBox pair and I would like to use the href parameter to make a popup when infoBox .

I use shinyBS for 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 realized that the href parameter works fine if we want to link on an external website, for example href = "http://stackoverflow.com/" but I did not know how to set the link in the internal link of the application.

EDIT

I am doing this editing because I have found a solution that makes the window accessible and makes it brilliant, thinking it is an action button by adding two variables to the valueBox output list.
- class action-button
- id , which allows us to use the observation or observation function to detect when the value cell clicks.

Here is a reproducible 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) 
+5
source share
3 answers

I decided to change the method. Now I have an actionbutton (or actionLink) inside the lookup element in the value field and create the bsModal element associated with this actionButton element.
If you are not familiar with the ShinyBS package, it allows you to create popover, tooltip, etc. functions. Without including HTML or java.

I follow the advice of @Mikko Martila Brilliant: adding addPopover to actionLink , and here is a reproducing example to show you my problem:

 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() parameter to add my button to the subheading field of the values.

This is not exactly what I wanted, but it does the job.

You can do this with actionLink (it looks better) using subtitles 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>") 
+1
source

I only know a bad option

1) add the tags$script(HTML("function clickFunction(link){ Shiny.onInputChange('linkClicked',link); }")) function tags$script(HTML("function clickFunction(link){ Shiny.onInputChange('linkClicked',link); }"))

2) edit the href children of your value Box

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,{..})

+2
source

I was stuck with the same problem and, after going through this link, I just started it without adding a separate button like this. Hope this helps someone who wants to solve a similar problem.

 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) 
+2
source

Source: https://habr.com/ru/post/1238933/


All Articles