shiny: open new browser tab from within shiny app

前端 未结 3 1160
别那么骄傲
别那么骄傲 2021-02-06 16:27

From within shiny I want to open a HTML page in a new browser tab. Here it is pointed out that I need JS for that task. Let\'s say I want to open the URL http://www.google.com

相关标签:
3条回答
  • 2021-02-06 16:27

    I was having a problem similar to this so I thought I would add my solution.

    I wanted to have links in the tabPanel but Shiny will open a new blank page and have a link instead of just clicking on the tabPanel and opening a new page. Using the standard bootstrap CSS the workaround is to use the navbarMenu and then put the links in the tabPanel.

    navbarMenu("Links",
               tabPanel(
                   a("Google", href="https://google.com", target="_blank")
               )
    
    0 讨论(0)
  • 2021-02-06 16:27

    I have the same problem and have come to the following solution. It's a bit of a workaround but it still works. @MarkHeckmann: To start a new BrowserTab from a running Shiny App I use an action button which triggers the function browseURL(...)

    library(shiny)
    ui <- fluidPage(
      titlePanel("Browser test"),
        sidebarLayout(
          sidebarPanel(
            shiny::actionButton(inputId = "gen_report", label = "Generate Report")
         ),
         mainPanel(   )
      ))
    
    server <- function(input, output) {
    observeEvent(input$gen_report,{
        browseURL("https://www.r-project.org")
    })
    }
    
    shinyApp(ui = ui, server = server)
    

    @RickTastic: This procedure also works with self generated HTML reports. By listing an html page instead of a web address. browseURL("test.dashboard.html") or browseURL("path to html file")

    0 讨论(0)
  • 2021-02-06 16:42

    You shouldn't need anything more fancy than traditional, shiny-ified HTML:

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

    You're just looking to set the target attribute on the a tag which tells your browser where to open this new link you created.

    0 讨论(0)
提交回复
热议问题