Add Dynamic URL Link

1,743 views
Skip to first unread message

Preston Smith

unread,
Mar 31, 2015, 12:50:08 PM3/31/15
to shiny-...@googlegroups.com
Hi, I'm trying to have a link that dynamically changes depending on a select input. When I try to make the href text output, the link doesn't work. I've attached a small example of my problem. Any ideas?

Thanks!


## server.r
shinyServer(function(input, output) {

    output$test <- renderText({input$select})
    
    output$url <- renderText({
        paste0("https://",input$select)
        
    })   
    
    
})




## ui.r
shinyUI(pageWithSidebar(
    headerPanel('Example'),
    sidebarPanel(
        selectInput("select", label = h3("Select Your Site"), 
                    choices = list("Google" = "www.google.com/", 
                                   "Images" = "www.google.com/imghp"), 
                    "www.google.com/")
    ),
    mainPanel(
        tabsetPanel(
            tabPanel("Example",
                     p(textOutput('test')),
                     p(textOutput('url')),
                     p(a("Dynamic site link", href = textOutput('url'), target = "_blank")),
                     p(a("Static site link", href = "https://www.google.com/", target = "_blank"))
                     
            )
        )
    )
))
server.R
ui.R

Greg L

unread,
Apr 6, 2015, 2:08:26 PM4/6/15
to shiny-...@googlegroups.com
well first of all, there's nothing in your text output that indicates you even want it as a link. it's just plain text right now. you're going to have to put the html in there to make it a link.
textOutput escapes html before outputting though, so you'll have to use uiOutput or htmlOutput for this. you could try 
renderUI({ 
          HTML(paste0('<a href = "linkblabla', input$select, '"> linkblabla </a>'))
})

Preston Smith

unread,
Apr 6, 2015, 5:58:28 PM4/6/15
to shiny-...@googlegroups.com
Thanks Greg!

Marcin Pilarczyk

unread,
Jun 26, 2015, 9:55:58 AM6/26/15
to shiny-...@googlegroups.com
Or try dynamic input fields
Reply all
Reply to author
Forward
0 new messages