Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open URL by tabPanel in Shiny

Tags:

r

shiny

My Attempt:

library(shiny) 

ui <- fluidPage(   
navbarPage("Sales Dashboard", id ="sales_tab",
  tabPanel("Panel_1", "Test Panel", value = "Test_panel"),
  tabPanel("Open Sales Gsheet", "Open Sales Gsheet", value = open_ghseet_tab")
))

server <- function(input, output, session) {
  observeEvent(input$sales_tab,{
  if(input$sales_tab == "open_ghseet_tab") {
  a("test", href="http://google.com", target="_blank")
  }
})   
}

shinyApp(ui = ui, server = server)

My Question:

When I click the tabPanel "Open Sales Gsheet" which has the value "open_gsheet_tab". All I want is to open a url which in example is google.com

I do not want to use actionbutton, it needs to be tabPanel based.

like image 583
Vasim Avatar asked Jan 04 '23 22:01

Vasim


1 Answers

There are actually many ways to do it.

(1)

library(shiny) 

ui <- fluidPage(   
  navbarPage("Sales Dashboard", id ="sales_tab",
             tabPanel("Panel_1", "Test Panel", value = 1),
             tabPanel("Open Sales Gsheet", "Open Sales Gsheet", value = 2,
                      uiOutput("Link"))
             ))

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

                        output$Link <- renderUI({

                          a("test", href="http://google.com", target="_blank")

                        })}

                      shinyApp(ui = ui, server = server)

(2)

library(shiny) 

ui <- fluidPage(   
  navbarPage("Sales Dashboard", id ="sales_tab",
             tabPanel("Panel_1", "Test Panel", value = 1),
             tabPanel("Open Sales Gsheet",a("test", href="http://google.com", target="_blank"))
             ))

                      server <- function(input, output, session) {}

                      shinyApp(ui = ui, server = server)

(1) and (2): There is a link, which appears only in the tab "Open Sales Gsheet"

Or You can have directly link inside of the navbarPage menu:

(3)

library(shiny) 

ui <- fluidPage(   
  navbarPage("Sales Dashboard", id ="sales_tab",
             tabPanel("Panel_1", "Test Panel", value = 1),
             tabPanel(a("Open Sales Gsheet", href="http://google.com", target="_blank"))
             ))

                      server <- function(input, output, session) {}

                      shinyApp(ui = ui, server = server)

(3) walkaround --> not distorted navbar menu

 library(shiny) 

ui <- fluidPage(   
  navbarPage("Sales Dashboard", id ="sales_tab",
             tabPanel(title=HTML("Panel_1</a></li><li><a href='http://google.com' target='_blank'>test"))
  ))
server <- function(input, output, session) {}

                      shinyApp(ui = ui, server = server)
like image 62
Mal_a Avatar answered Jan 12 '23 00:01

Mal_a