Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change background of Leaflet map in RStudio?

Tags:

r

leaflet

shiny

I'm creating a Shiny App using a leaflet widget. My map has a simple Shapefile with no basemap engaged. Leaflet renders a default grey background. I would like to change the background to white.

I see some answers using javascript code, but I am unfamiliar how to implement this in the R language.

like image 634
Natalie Pace Avatar asked Apr 17 '17 00:04

Natalie Pace


People also ask

How do I create a Leaflet map in R?

Easily render spatial objects from the sp or sf packages, or data frames with latitude/longitude columns To install this R package, run this command at your R prompt: Once installed, you can use this package at the R console, within R Markdown documents, and within Shiny applications. You create a Leaflet map with these basic steps:

How do I create a basemap in leaflet?

Leaflet supports basemaps using map tiles, popularized by Google Maps and now used by nearly all interactive web maps. Default (OpenStreetMap) Tiles The easiest way to add tiles is by calling addTiles()with no arguments; by default, OpenStreetMaptiles are used.

How can I change the appearance of the RStudio?

Here is the question. How I can change the appearance of the Rstudio. I want my R studio to appear as the code editor and the environment with a black background color. The console and plot area as a white background. Thank you! Tools > Global Options > Appearance lets you choose themes.

What is the leaflet R package?

This R package makes it easy to integrate and control Leaflet maps in R. Easily render spatial objects from the sp or sf packages, or data frames with latitude/longitude columns To install this R package, run this command at your R prompt:


1 Answers

You can change the Leaflet default background color with CSS, see this related question.

You can use custom CSS in your Shiny app by adding it into the HTML head of the Shiny output:

ui <- fluidPage(
  tags$head(
    tags$style(HTML(".leaflet-container { background: #f00; }"))
  ),
  # etc.
)
# etc.

Other possibilites for adding styles, for example with external CSS files, are explained in the Shiny documentation.

like image 121
chrki Avatar answered Sep 28 '22 03:09

chrki