I'm trying to add a checkboxInput onto my leaflet map using addControl. I'm having trouble making a reprex, since it works ok in the example below (although the right hand padding is excessive). But in my actual app I get lots of white space all around the checkbox and it's really ugly. How do I fix this? I haven't had any luck with changing my css file. I believe it uses css classes info and legend. I don't want to mess up my legend though.
library(shiny)
library(leaflet)
dlat <- 1 / 111000 * 100 # degrees per metre
n <- 10000 # number of circles
mylng <- 175.322 + (runif(n) * 2 - 1) * dlat * 6
mylat <- -37.789 + (runif(n) * 2 - 1) * dlat * 1.5
hex <- c(0:9, LETTERS[1:6])
ui <- fluidRow(
tags$h2("Leaflet in Shiny"),
actionButton("plotbutton", label = "Recolour Markers"),
leafletOutput("map")
)
server <- function(input, output, session) {
output$map <- renderLeaflet({
cat("renderLeaflet\n")
leaflet() %>%
addTiles() %>%
setView(175.322, -37.789, zoom = 17) %>%
addControl(
checkboxInput("linestype", strong("My checkbox"), value = FALSE),
position="bottomright"
)
})
observeEvent(input$plotbutton, {
cat("input$plotbutton\n")
col <- paste0("#", paste0(sample(hex, 6, replace = TRUE), collapse = ""))
leafletProxy("map") %>%
clearShapes() %>%
addCircles(
lng = mylng,
lat = mylat,
radius = 1,
color = col)
})
}
shinyApp(ui = ui, server = server)
Edit: This file has some css that the author used.