45

My code:

library(shiny)
runApp(
  list(ui = fluidPage(
     uiOutput("tab")
    ),
  server = function(input, output, session){
    url <- a("Google Homepage", href="https://www.google.com/")
    output$tab <- renderUI({
      paste("URL link:", url)
    })
  })
)

Current output:

URL link: <a href="https://www.google.com/">Google Homepage</a>

Desired output:

URL link: Google Homepage

where Google Homepage is a clickable hyperlink.

I'm currently using the renderUI/uiOutput duo as instructed here: how to create a hyperlink interactively in shiny app?

2 Answers 2

58

By using paste, you're treating the url as a string. The function you want to use here is tagList:

runApp(
  list(ui = fluidPage(
     uiOutput("tab")
    ),
  server = function(input, output, session){
    url <- a("Google Homepage", href="https://www.google.com/")
    output$tab <- renderUI({
      tagList("URL link:", url)
    })
  })
)
Sign up to request clarification or add additional context in comments.

1 Comment

How to ensure the url link is opened inside the SHiny app and not a new tab?
35

You can use html tags whatever you want to tag

    tags$a(href="www.rstudio.com", "Click here!")
## <a href="www.rstudio.com">Click here!</a>

2 Comments

Also, to open it in a new browser, adding target="_blank" as argument.
would you know how to change the font size if we use your tags$a solution? Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.