I have a simple shiny app that plots points from a csv file input. Currently, when I upload the file to the shiny app, the map doesn't do anything. I think this is because the leaflet map isn't reacting to the file being uploaded. How might I be able to fix this?
See my code below. Sample data can be found HERE.
library(shiny)
library(shinydashboard)
library(leaflet)
library(dplyr)
library(htmltools)
shinyApp(
ui <- fluidPage(
titlePanel("eBird Visualizer"),
fileInput("MyEBirdData_in", "MyEBirdData", buttonLabel = "Upload a .csv",
placeholder = "No File Selected...", width = "255px",
accept = ".csv"),
leafletOutput("myMap")
),
server = function(input, output) {
output$contents <- renderTable({
inFile <- input$MyEBirdData_in
if (is.null(inFile))
return(NULL)
myData = read.csv(inFile$datapath, header = input$header)
df0 = data.frame(myData$Submission.ID, myData$Latitude, myData$Longitude)
df = unique(df0)
names(df)[2] = 'latitude'
names(df)[3] = 'longitude'
})
output$myMap = renderLeaflet({
leaflet(data = df) %>% addProviderTiles(providers$CartoDB.Positron)
})
}
)
reactiveValues- SBista