I'm creating an RShiny application that is supposed to have four components, two tmaps across the top row and two gauges (from the C3 package) on the bottom row, from the data package I commented out. The plots are working fine but for some reason, when I tried to add a title to the tmap in the top right, that title displayed underneath the title for the top left tmap. What is causing that?
Code below:
library(shiny)
#devtools::install_github("FrissAnalytics/shinyJsTutorials/widgets/C3")
#devtools::install_github("ccebra/Divvy-Data") # Divvy data package
library(C3) # for gauge plots
library(devtools)
library(divvymos)
library(tmap)
months = c('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')
years = c('2013','2014','2015','2016','2017','2018','2019','2020','2021','2022')
ui <- fluidPage(
titlePanel("Divvy Bike Data by Month"),
sidebarLayout(
sidebarPanel(
selectInput("codeInput1", label = "Select Month", choices = months),
selectInput("codeInput2", label = "Select Year", choices = years),
),
mainPanel(
tabPanel("Maps", fluidRow(
column(6, tmapOutput("map1", width = "100%", height = 600)),
column(6, tmapOutput("map2", width = "100%", height = 600)),
column(6, C3GaugeOutput("gauge1",width = "100%", height = 200)),
column(6, C3GaugeOutput("gauge2",width= "100%", height = 200))))
)
)
)
server <- function(input, output) {
data <- reactive(
return(get(paste(input$codeInput1,substr(input$codeInput2,3,4),sep="")))
)
title <- paste(toTitleCase("Gaussian Kernel with Bandwidth 2500"))
output$map1 <- renderTmap({tm_shape(chib) +
tm_borders() +
tm_shape(statsf(data())) +
tm_bubbles(
size = "total",
col = "pctelectric",
alpha = 1) +
tm_layout(legend.position = c("right", "top"), title= "Divvy Stations (sized by number of rides)", title.position = c('right', 'top'))
})
output$map2 <- renderTmap({tm_shape(choynowski(data())) +
tm_fill("sig",style="cat") +
tm_borders() +
tm_shape(statsf(data())) +
tm_dots(size=0.009) +
tm_layout(legend.position = c("right", "top"), title= "Choynowski map of active stations", title.position = c('right', 'top'))
})
output$gauge1 <- renderC3Gauge(C3Gauge(trunc(10000*(bufferArea(data())))/100))#Truncate to 2 decimal places
output$gauge2 <- renderC3Gauge(C3Gauge(trunc(10000*(totalRides(data())/1644809))/100))#Truncate, 1644809 is max rides (July 2021)
}
shinyApp(ui = ui, server = server)