valueBox() for hyperlink and output should be shown another window.

I want to render a website through 'valueBox' as a hyperlink. Here below is the code:

library(shiny)
library(shinydashboard)

ui = shinyUI(dashboardPage(
  dashboardHeader(title = "sam"),
  dashboardSidebar( ),
  dashboardBody(
           fluidRow(
      valueBox("100", subtitle = tags$p("Attendance", style = "font-size: 200%;"),
           icon = icon("trademark"), color = "yellow", width = 4,
           href = "https://economictimes.indiatimes.com/")
    ) )))

server <- shinyServer(function(input, output) {

})

shinyApp(ui,server)

I want that output should shown in another window, just like pop-up window.

Hi @sankarachari, just to make sure I understand, when you click on the valueBox(), you want the href to open in another window within your application's page? Or are you wanting to open another browser window?

browser window

Thanks for replying.

This is a bit of a hack (it makes assumptions about the HTML structure used internally by shinydashboard::valueBox()), but you could get it working by adding some custom JavaScript...something like this:

document.querySelector(".small-box").parentNode.setAttribute("onclick", "window.open('https://economictimes.indiatimes.com', 'newwindow', 'width=300,height=250'); return false;")

(NOTE: if you wanted multiple valueBox()s to open multiple different links, that JS would have to be a bit more sophisticated)

If you put that in a file www/open-window.js alongside your app.R that has:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "sam"),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      valueBox("100", subtitle = tags$p("Attendance", style = "font-size: 200%;"),
               icon = icon("trademark"), color = "yellow", width = 4)
    ),
    tags$script(src = "open-window.js")
  )
)

server <- function(input, output) {

}

shinyApp(ui,server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.