I am trying to compare two thematic maps using tmap package in Shiny. However I got an error argument length zero. Also I want to plot these two maps from selecting Shinyinput panel.I mean from 4 inputs 2 combinations of 4 plot can be drawn.The plot must be drawn when the length of input$hafta is equal to 2. I send you the data type and code that I wrote.
PS: I tried with using facets in tmap however as far as I found out that shiny does not support it. Thank you
str(turcov@data)
'data.frame': 81 obs. of 16 variables:
$ NAME_1 : chr "Adana" "Adıyaman" "Afyon" "Ağrı" ...
$ GID_0 : chr "TUR" "TUR" "TUR" "TUR" ...
$ NAME_0 : chr "Turkey" "Turkey" "Turkey" "Turkey" ...
$ GID_1 : chr "TUR.1_1" "TUR.2_1" "TUR.3_1" "TUR.4_1" ...
$ VARNAME_1: chr "Seyhan" "Adıyaman" "Afyonkarahisar" "Ağri|Karaköse" ...
$ NL_NAME_1: chr NA NA NA NA ...
$ TYPE_1 : chr "Il" "Il" "Il" "Il" ...
$ ENGTYPE_1: chr "Province" "Province" "Province" "Province" ...
$ CC_1 : chr NA NA NA NA ...
$ HASC_1 : chr "TR.AA" "TR.AD" "TR.AF" "TR.AG" ...
$ sub4 : num 41.2 116.2 38.4 19 123.1 ...
$ mart1 : num 63 154.6 47.5 22.2 173.5 ...
$ fark : num 52.8 33.1 23.6 16.9 41 ...
$ kategori : Factor w/ 2 levels "artış","azalış": 1 1 1 1 1 1 1 1 1 1 ...
$ mart2 : num 63 154.6 47.5 22.2 173.5 ...
$ mart3 : num 61.6 169.8 47.4 41.5 214.4 ...
library(rgdal)
library(sp)
library(spdep)
library(ggplot2)
library(raster)
library(tmap)
library(plotly)
library(reshape2)
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("hafta", "Hafta seçiniz:", choices=c("sub4","mart1","mart2","mart3")
,selected=NULL,multiple=TRUE,selectize = TRUE)),
mainPanel(
tabsetPanel(
tabPanel("İki hafta il sınıflandırma karşılaştırması",
tmapOutput("map1", width = "100%", height = 800)),
tabPanel("Artış-azalış ve Artış-azalış yüzdeleri",
tmapOutput("map2", width = "100%", height = 800)),
tabPanel("İl ve komşuları haftalık vaka trendi",
plotlyOutput("map3", width = "100%", height = 800))
)
)))
server <- function(input, output) {
output$map1<-renderTmap({ print(input$hafta)
breaks<-c(0,20,50,100,Inf)
renk=c("blue","yellow","orange","red")
tmap1<-tmap_mode("view")+
tm_shape(turcov) +
tm_fill(input$hafta[1],breaks = breaks,
title=c(" İllere göre 100 binde vaka sayıları(input$hafta[1])"),palette = renk) +
tm_borders() +
tm_text("NAME_1")
tmap2<-tmap_mode("view")+
tm_shape(turcov) +
tm_fill(input$hafta[2],breaks = breaks,
title=c(" İllere göre 100 binde vaka sayıları(input$hafta[1])"),palette = renk) +
tm_borders() +
tm_text("NAME_1")
tmap_arrange(tmap1,tmap2,ncol=2)
})
}
shinyApp(ui = ui, server = server)