4

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.

Vasim
  • 3,052
  • 3
  • 35
  • 56

1 Answers1

10

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)
Mal_a
  • 3,670
  • 1
  • 27
  • 60
  • It is the 3rd option that I'm looking for. It does work; however; the output is not in perfect align as seen in this [image](https://s27.postimg.org/c65gfaj8j/Capture.png) – Vasim Dec 13 '16 at 08:39
  • 3 not distorted - produces two tabPanels one as Panel_1 and other as test. The test panel opens the href. We don't need two panels and how do I rename test? – Vasim Dec 14 '16 at 07:55
  • In your question code there are two TabPanels: Panel_1 and Open Sales Gsheet, as well in the image you have posted as a comment are three TabPanels..Eitherway the 3 solution is a bit of a trick, i have created using HTML list items including Panel_1 and test. So you have sort of only one TabPanel (Panel_1) and next to it a link. To change the name test to smthg else, just change the text: test, which is written at the end of the HTML tag: `HTML("Panel_1
  • test")`<---
  • – Mal_a Dec 14 '16 at 08:08