I have created a simple shiny app where I have country, name, and month as inputs according to which a certain map is plotted.
What I would like to do, is to draw cubic 50*50 km grids over each base map.
I have as data, the coordinates of the centroid of each grid, a certain value to plot per grid (filtered per year and month)
What I have till now, is the filter inputs and the base maps, still have no clue how to dram the grids over the map.
Any help is appreciated
Here is part of my code:
ui<- dashboardPage(skin="purple",
dashboardHeader(title=""),
dashboardSidebar(sidebarMenu(
menuItem("",tabName="",icon =icon("dashboard"))
)),
dashboardBody(
tabItem(tabName="",
fluidRow(
box(title="Please choose a country,month and year", width=12,status="warning",solidHeader=TRUE,
selectInput("Country","Country",choices=countries_list, multiple=FALSE),
selectInput("Month","Month",choices=month_list,multiple=FALSE),
selectInput("Year","Year",choices=year_list,multiple=FALSE),
downloadButton("DownloadData","Download Data as csv"))
),
fluidRow(
box(title="Grids",width=12,highchartOutput("Map",height=450),status="primary",solidHeader=TRUE)
)
)
)
)
# Server input/output Function ---------------------------------------------------------
server<-function(input,output){
#Interactive filters & base Maps & Grids
data1<-reactive(
{
req(input$Country)
req(input$Month)
req(input$Year)
data_filtered<- df_Main%>%filter(country %in% input$Country)%>%filter(month_name %in% input$Month)%>%filter(year %in% input$Year)
}
)
output$Map <- renderHighchart(
{
if(input$Country=="Algeria"){
hcmap("https://code.highcharts.com/mapdata/countries/dz/dz-all.js")%>%hc_title(text = "Algeria")
}
else if(input$Country=="Bahrain"){
hcmap("https://code.highcharts.com/mapdata/countries/bh/bh-all.js")%>%hc_title(text = "Bahrain")
}
else if(input$Country=="Comoros"){
hcmap("https://code.highcharts.com/mapdata/countries/km/km-all.js")%>%hc_title(text = "Comoros")
}
else if(input$Country=="Djibouti"){
hcmap("https://code.highcharts.com/mapdata/countries/dj/dj-all.js")%>%hc_title(text = "Djibouti")
}
else if(input$Country=="Egypt"){
hcmap("https://code.highcharts.com/mapdata/countries/eg/eg-all.js")%>%hc_title(text = "Egypt")
}
else if(input$Country=="Iraq"){
hcmap("https://code.highcharts.com/mapdata/countries/iq/iq-all.js")%>%hc_title(text = "Iraq")
}
else if(input$Country=="Jordan"){
hcmap("https://code.highcharts.com/mapdata/countries/jo/jo-all.js")%>%hc_title(text = "Jordan")
}
else if(input$Country=="Kuwait"){
hcmap("https://code.highcharts.com/mapdata/countries/kw/kw-all.js")%>%hc_title(text = "Kuwait")
}
else if(input$Country=="Lebanon"){
hcmap("https://code.highcharts.com/mapdata/countries/lb/lb-all.js")%>%hc_title(text = "Lebanon")
}
else if(input$Country=="Libya"){
hcmap("https://code.highcharts.com/mapdata/countries/ly/ly-all.js")%>%hc_title(text = "Libya")
}
else if(input$Country=="Mauritania"){
hcmap("https://code.highcharts.com/mapdata/countries/mr/mr-all.js")%>%hc_title(text = "Mauritania")
}
else if(input$Country=="Morocco"){
hcmap("https://code.highcharts.com/mapdata/countries/ma/ma-all.js")%>%hc_title(text = "Morocco")
}
else if(input$Country=="Oman"){
hcmap("https://code.highcharts.com/mapdata/countries/om/om-all.js")%>%hc_title(text = "Oman")
}
else if(input$Country=="Qatar"){
hcmap("https://code.highcharts.com/mapdata/countries/qa/qa-all.js")%>%hc_title(text = "Qatar")
}
else if(input$Country=="Saudi Arabia"){
hcmap("https://code.highcharts.com/mapdata/countries/sa/sa-all.js")%>%hc_title(text = "Saudi Arabia")
}
else if(input$Country=="Somalia"){
hcmap("https://code.highcharts.com/mapdata/countries/so/so-all.js")%>%hc_title(text = "Somalia")
}
........
}
)
#Downloadable data .csv format
output$DownloadData <- downloadHandler(
filename = function() {
paste0(Sys.time(), ".csv", sep = "")
},
content = function(file) {
data_filtered<-df_Main %>%filter(month_name %in% input$Month)%>%filter(year %in% input$Year)%>%filter(country %in% input$Country)
write.csv(data_filtered, file)
}
)
}
# Call Server -------------------------------------------------------------
shinyApp(ui,server)```