Update docs/source/r.rst

This commit is contained in:
AcuGIS 2024-09-01 15:01:20 +00:00
parent 8088614f0a
commit 0c073e3ccb
1 changed files with 105 additions and 29 deletions

View File

@ -143,7 +143,7 @@ The output should look as below:
R Plotly
===================================
To create an R Leaflet Map, click on "Add New" button.
To create an R Plotly App, click on "Add New" button.
.. image:: images/Add-Map.png
@ -156,13 +156,83 @@ Give your R code a Name and Description.
Example
--------------
The three main components are the plotly, ggplot2, and htmlwidgets function.
The example is animated Plotyl map with Play button.
The three main components in this example are the plotly, dplyr, and htmlwidgets function.
.. code-block:: R
# Main libraries for Plotly
library(dplyr)
library(plotly)
library(htmlwidgets)
# Your R Code Here
#saveWidget
htmlwidgets::saveWidget(as_widget(p), file="index.html")
An example of a Plotly app is included in the installation. Here, we add the RPostgreSQL library to connect to PostgreSQL.
.. code-block:: R
#load library
library(dplyr)
library(plotly)
library(htmlwidgets)
#load data
df <- read.csv("graph.csv")
#create map
p <- plot_geo(df, locationmode = 'world') %>%
add_trace( z = ~df$new_cases_per_million, locations = df$code, frame=~df$start_of_week, color = ~df$new_cases_per_million)
#export as html file
htmlwidgets::saveWidget(p, file = "index.html")
The output should look at below:
.. image:: images/R-Animated.png
R Plotly Dynamic Data
===================================
To create an R Plotyl App with Dynamic Data, 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
--------------
The example is animated Plotyl map with Play button.
The main components in this example are the plotly, ggplot2, RPostgreSQL, and htmlwidgets function.
.. code-block:: R
# Main libraries for Plotly
library(plotly)
library(ggplot2)
library(RPostgreSQL)
library(htmlwidgets)
# Your R Code Here
@ -181,7 +251,7 @@ An example of a Plotly app is included in the installation. Here, we add the RP
library(RPostgreSQL)
library(htmlwidgets)
conn <- RPostgreSQL::dbConnect("PostgreSQL", host = "localhost", dbname = "r_examples", user = "admin1", password = "4eA7hDlgYF")
conn <- RPostgreSQL::dbConnect("PostgreSQL", host = "localhost", dbname = "$DB_NAME", user = "$DB_USER", password = "$DB_PASS")
query_res <- dbGetQuery(conn, 'SELECT * FROM "sensor_readings";');
sensor_readings <- as.data.frame(query_res);
@ -207,6 +277,12 @@ An example of a Plotly app is included in the installation. Here, we add the RP
The output should look at below:
.. image:: images/R-Sensor.png
R Standard Plot (PNG)
===================================