In a Shiny app, I want to create a link dynamically using a URL loaded from a file. The link appears inside a conditionalPanel. In my first attempt, the ui portion looked like this:
conditionalPanel(condition = "input.myEvent",
fluidRow(column(12,tags$p(textOutput("description")))),
fluidRow(column(6, tags$a(href='http://www.google.com/', "Google"))),
fluidRow(column(6, tags$a(href="url", 'website'))),
while the server portion looked like this:
observeEvent(input$myEvent, {
p <- input$myEvent
description = c(data[data$Name == p, ]$Description)
output$description <- renderText(description)
url1 = c(data[data$Name == p, ]$Website)
output$url <- renderText(url1)
}
)
With this code, the URL is treated as the string "url" so it doesn't work.
I found another answer Create URL hyperlink in R Shiny?
however that example uses a static URL. I can't figure out how to make it dynamic. Here I made the UI section look like
uiOutput("url")
and the server section look like:
url <- a("website", href='url1')
output$url <- renderUI({
paste(url)
})
But again the url is just the string 'url1', and again the url renders as text, rather than an a clickable link. It seems close, but a) how do I set the value of href in this server code to be a variable? b) how do I make the output an actual html anchor tag rather than just text.