我的尝试:
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
。
答案 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)