我有一个简单的闪亮应用程序,可以从 csv 文件输入中绘制点。目前,当我将文件上传到闪亮的应用程序时,地图没有做任何事情。我认为这是因为传单地图没有对上传的文件做出反应。我怎么能解决这个问题?
请参阅下面的代码。样本数据可以在这里找到。
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)
})
}
)