QuartzMap/docs/source/r.rst

326 lines
6.7 KiB
ReStructuredText
Raw Normal View History

2024-08-25 21:12:30 +00:00
*******
R
*******
QuartzMap supports creating of a number of R HTML applications:
1. R Leaflet: https://github.com/rstudio/leaflet/
2. Plotly: https://plotly.com/r/
3. Standard Plots
.. contents:: Table of Contents
2024-08-31 22:56:25 +00:00
R Publishing
2024-08-25 21:12:30 +00:00
===================================
2024-08-31 22:56:25 +00:00
There are three options for publising your R code.
2024-08-25 21:12:30 +00:00
Option 1: FTP.
------------
2024-08-31 22:56:25 +00:00
FTP Uploads are R files you have uploaded directly via FTP.
2024-08-25 21:12:30 +00:00
It can also maps you uploaded via any FTP client.
.. image:: images/Map-2.png
Option 2: Archive (Upload)
------------
Archive is a zipped archive file you can upload.
.. image:: images/Map-3.png
Option 3: Paste
2024-08-31 22:56:25 +00:00
-----------------
2024-08-25 21:12:30 +00:00
Paste your R Leaflet code into the code box.
2024-08-31 22:39:35 +00:00
.. image:: images/R-Paste.png
2024-08-25 21:12:30 +00:00
2024-08-31 22:56:25 +00:00
R Leaflet
===================================
2024-08-25 21:12:30 +00:00
2024-08-31 22:56:25 +00:00
To create an R Leaflet Map, click on "Add New" button.
.. image:: images/Add-Map.png
2024-08-25 21:12:30 +00:00
2024-08-31 22:56:25 +00:00
FTP, Upload, or Paste your code.
2024-08-25 21:12:30 +00:00
2024-08-31 22:56:25 +00:00
Give your R code a Name and Description.
Example
--------------
2024-08-31 22:27:24 +00:00
The two main components are the libraries and saveWidget function
.. code-block:: R
#libraries
library(leaflet)
library(leaflet.extras)
require(sf)
library(htmlwidgets)
# Your R Code Here
#saveWidget
saveWidget(m, file = "index.html")
An example Choropleth map is included in the installation.
.. code-block:: R
library(leaflet)
library(leaflet.extras)
require(sf)
library(htmlwidgets)
# From https://leafletjs.com/examples/choropleth/us-states.js
states <- sf::read_sf("https://rstudio.github.io/leaflet/json/us-states.geojson")
bins <- c(0, 10, 20, 50, 100, 200, 500, 1000, Inf)
pal <- colorBin("YlOrRd", domain = states$density, bins = bins)
labels <- sprintf(
"<strong>%s</strong><br/>%g people / mi<sup>2</sup>",
states$name, states$density
) %>% lapply(htmltools::HTML)
m <- leaflet(states) %>%
setView(-96, 37.8, 4) %>%
addPolygons(
fillColor = ~pal(density),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlightOptions = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(pal = pal, values = ~density, opacity = 0.7, title = NULL,
position = "bottomright") %>%
addTiles(group="OpenStreetMap") %>%
addProviderTiles(providers$Esri.WorldImagery, group = "Esri World Imagery") %>%
addLayersControl(baseGroups=c("OpenStreetMap", "Esri World Imagery"), options=layersControlOptions(collapsed=FALSE)) %>%
addMeasurePathToolbar(options = measurePathOptions(imperial = FALSE, showDistances = TRUE)) %>%
addDrawToolbar(
targetGroup = "draws",
editOptions = editToolbarOptions(
selectedPathOptions = selectedPathOptions()))
saveWidget(m, file = "index.html")
2024-08-31 22:56:25 +00:00
R Plotly
===================================
To create an R Leaflet Map, click on "Add New" button.
.. image:: images/Add-Map.png
FTP, Upload, or Paste your code.
Give your R code a Name and Description.
Example
2024-08-25 21:12:30 +00:00
--------------
2024-08-31 22:56:25 +00:00
The three main components are the plotly, ggplot2, and htmlwidgets function
2024-08-25 21:12:30 +00:00
2024-08-31 22:56:25 +00:00
.. code-block:: R
# Main libraries for Plotly
library(plotly)
library(ggplot2)
library(htmlwidgets)
# Your R Code Here
2024-08-25 21:12:30 +00:00
2024-08-31 22:56:25 +00:00
#saveWidget
htmlwidgets::saveWidget(as_widget(p), file="index.html")
2024-08-25 21:12:30 +00:00
2024-08-31 22:56:25 +00:00
An example of a Plotly app is included in the installation.
.. code-block:: R
library(plotly)
library(ggplot2)
library(htmlwidgets)
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
p <- plot_ly(d, x=~carat, y=~price, text=~paste("Clarity: ", clarity), mode="markers", color=~carat, size=~carat)
htmlwidgets::saveWidget(as_widget(p), file="index.html")
2024-08-25 21:12:30 +00:00
There are three options for creating a Map.
Option 1: FTP.
------------
FTP Uploads are qgis2web maps you have uploaded directly via FTP.
It can also maps you uploaded via any FTP client.
.. image:: images/Map-2.png
Option 2: Archive (Upload)
------------
Archive is a zipped archive file you can upload.
.. image:: images/Map-3.png
Option 3: Paste
------------
Paste your R Leaflet code into the code box.
.. image:: images/Map-3.png
Name
--------------
Give your map a name. The name will appear as the map title on the dashboard.
.. image:: images/Name-Desc.png
Description
--------------
The Description is the text that will appear at the bottom of the map link
.. image:: images/Name.png
Data
--------------
The Data section is where you can connect your map layers to their Data Sources to make them dynamic.
.. image:: images/PostGIS-Select.png
Layer Cache
--------------
When you connect your map to a PostGIS Data Source, you have the option of caching layers for better performance.
By default, cache is disabled.
You can enable caching on a per Layer basis by specifying the cache interval.
When set, this is the interval at which your map will check the database for updates.
.. image:: images/cache.png
If you have enabled cache and wish to clear it, you can do so by clicking the Clear Cache icon on the Map page:
.. image:: images/clear-cache.png
QGIS Project File:
--------------
You can upload your QGIS Project file in order to use WMS, WFS, and WMTS
.. image:: images/QGIS-Project-File.png
Map CSS:
--------------
Enter any custom CSS for your map that wish to.
.. image:: images/CSS.png
Thumbnail Image:
--------------
Upload a thumbnail image for your map to be displayed on the home page.
.. image:: images/Thumbnail.png
Data Tables:
--------------
Check the "Show Data Tables" box in order to provide users with data in table format.
.. image:: images/Show-Data-Table.png
Info Box.
--------------
The InfoBox is a modal information box you can display to map users.
.. image:: images/Info-Box.png
Security
--------------
Maps can be Private or Public.
The Security section is where you assign permissions to your map.
Security is Group based, so any users belonging to the Group will be able to view the map.
.. image:: images/users-3.jpg
1. Private Maps
Private maps can be viewed by the user logging into your map portal or via Secure Share link (for temporary access)
For example, since we gave access to the Group containing user Jane Doe, when she logs in she will see only the two maps she has permissions to
.. image:: images/users-2.jpg
2. Public Maps
You can also tick the “Public” box to make your map public.
.. image:: images/public-users.jpg
If your map is “Public”, you can use the map url to display the map.
By default, the map is full screen. You can also use an iframe like below:
.. image:: images/public-map.png