Hello,
I am attempting to calculate the distance between two addresses with gmapdistance in a shiny app. I have the code working in an r script and not in a shiny app:
distance <- function(addr1, addr2) {
meters <- gmapsdistance(origin = "addr1",
destination = "addr2",
mode = "driving",
key = Sys.getenv("KEY"))$Distance
miles <- meters/1609.34
return(miles)
However, when I put this in a shiny app, nothing happens. Here is my code:
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput(inputId = "addr1",
label = h4("Enter address 1:"),
value = ""),
textInput(inputId = "addr2",
label = h4("Enter address 2:"),
value = "")
),
mainPanel(
textOutput("value")
)
)
)
server <- function(input, output) {
output$value <- renderText({
meters <- gmapsdistance(origin = "addr1",
destination = "addr2",
mode = "driving",
key = ("KEY"))$Distance
miles <- meters/1609.34
return(miles)
})
}
shinyApp(ui, server)
any insight into how to fix this would be much appreciated, thanks!!!