#加载所需的软件包
library(shiny)
library(leaflet)
library(leaflet.extras)
library(jsonlite)
# 图形用户界面
ui <- fluidPage(
titlePanel("This is a simple visualization Shiny-App"),
p("Please upload your input in a csv file"),
p("The columns must contain a) longitude, b) latitude, c) observation intensity score or count for each location"),
fileInput(inputId="input_file",label="Please upload input data",placeholder=""),
checkboxInput(inputId="input_header",label="Does your .csv-file have headers?",value=TRUE),
leafletOutput(outputId = "map_result"),
p(""),
actionButton(inputId="input_button",label="Visualize")
)
# 服务器
server <- function(input,output){
output$map_result <- renderLeaflet({
#号召性用语按钮
input$input_button
#读取和处理输入数据
isolate({
data_file <- req(input$input_file)
if(is.null(data)){
return(NULL)
}else{
data <- read.csv(file=data_file$datapath,header=input$input_header)
}
#可视化输出数据
leaflet() %>%
addProviderTiles(provider=providers$Hydda) %>%
setView(lng= mean(data[,1]), lat=mean(data[,2]), zoom=6) %>%
addHeatmap(lng =data[,1] , lat=data[,2] , intensity=data[,3])
})
})
}
# 应用程序
shinyApp(ui=ui,
server=server)
专业领域为优化和仿真的工业工程师(R,Python,SQL,VBA)
Leave a Reply