在Shiny中通过tabPanel打开URL

时间:2016-12-13 07:49:56

标签: r shiny

我的尝试:

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)

我的问题:

点击tabPanel "Open Sales Gsheet",其值为"open_gsheet_tab"。我想要的只是打开一个网址,例如google.com

我不想使用actionbutton,它需要基于tabPanel

1 个答案:

答案 0 :(得分:6)

实际上有很多方法可以做到。

<强>(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)(2):有一个链接,只显示在标签"Open Sales Gsheet"

或者您可以直接链接到navbarPage菜单中:

<强>(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 - &gt;没有扭曲的导航栏菜单

 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)