0
votes

How do I create a working hyperlink within shiny and leaflet from information from a column from a csv file?

Say I have a csv InputFile as input into a Shiny and Leaflet app that looks like this...

Site#   Lat                  Long                  Link
1       41.9582781716978,   -112.15752297501899    <a href="https://google.com">Link</a>
2       41.9582781716978,   -112.15752297501899    <a href="https://rstudio.github.io/leaflet/">Link</a>
etc

I'd like to create a map via leaflet with the hyperlink in the popup, but I can't get it work. Every time the returning popup string contains additional information about the local host or the shinyapp host, rather than just the html string I have in my InputFile (example, returned as https://shinyapps.io/appexample/https://google.com),

#Example Code
library(shiny) 
library(leaflet) 

FileInput <- read.csv("inputfile.csv")

ui <- fluidPage(leafletOutput("mapA")))

server <- function(input, output) {
    output$mapA <- renderLeaflet({
      leaflet(data = FileInput) %>%
       addTiles("Title of Map") %>%
       addCircleMarkers(
          lng = FileInput$Long, 
          lat = FileInput$Lat,
          popup = FileInput$Link)
    )}
    }

shinyApp(ui = ui, server = server)
1
Would you be able to add the result of dput(head(FileInput)) to your question to make reproducible? - Ben

1 Answers

0
votes

Ah ha. Good catch by @Ben, the string I was creating for my Link column in my FileInput.csv was incorrect, it keep including additional quotation marks, which I only noticed doing a dput(head(FileInput)). I was able to do a little string manipulation and make it work.