pssguy
pssguy

Reputation: 3505

Having difficulty with adding a variable to a url link in shiny uiOutput

I am trying to create a link to twitter pages based on a selectInput selection. I have a data.frame, df, with columns of names and related screenNames

So in ui.R have

selectInput("name","Tweeter",personChoice, selected="Jane Doe"),
uiOutput('twitterLink')

and in server.R

output$twitterLink <- renderUI({

  twitterUrl <-df[df$name==input$name,]$screenName 
  print(twitterUrl #jdoe

# a("Twitter", class="web", href="https://twitter.com/jdoe") Hard code works

  paste0('a(\"Twitter\", class=\"web\", href=\"https://twitter.com/',twitterUrl,'\")')

})

results in the text

a("Twitter", class="web", href="https://twitter.com/jdoe") in the browser

tags$body(uiOutput('twitterLink')) 

does not affect the outcome

TIA

Upvotes: 0

Views: 747

Answers (1)

jdharrison
jdharrison

Reputation: 30425

a is a function which outputs the appropriate html:

> a("Twitter", class="web", href="https://twitter.com/jdoe")
<a class="web" href="https://twitter.com/jdoe">Twitter</a> 

your renderUI should be of the form:

  output$twitterLink <- renderUI({

    twitterUrl <-df[df$name==input$name,]$screenName 
    a("Twitter", class = "web", href = paste0('"https://twitter.com/', twitterUrl, '")')

  })

Upvotes: 2

Related Questions