A recap on R Language.

A recap on R Language.

January 10, 2025

Its been a while since I have done some project/tasks with R.

But recently, I had an idea to put a Flexdashboard inside a mdx post for Astro websites.

And this thing worked perfectly…

But how can explain to someone whats going on?

Well…

R Setup

sudo apt update
sudo apt install -y software-properties-common apt-transport-https
sudo apt update
sudo apt install r-base #this is ~150mb to get installed
sudo apt install pandoc #and this around ~200mb

See that R is ready with:

R --version

Right now im getting the 4.3.3 R version for x86.

IDE Setup

As always, anything will work…but vscode was not the popular one for R.

I used RStudio, which has been renamed to post

wget https://download1.rstudio.org/electron/jammy/amd64/rstudio-2024.12.0-467-amd64.deb
sudo dpkg -i rstudio-2024.12.0-467-amd64.deb
sudo apt-get install -f #with dependencies
rstudio #open it
R.version #test the R CLI inside rstudio

https://posit.co/download/rstudio-desktop/

https://www.youtube.com/watch?v=k0r3iLGJgmQ

https://posit.co/blog/rstudio-is-now-posit/

Where are we working now?

getwd()
setwd("~/Documents/acoolproject")

R Dependencies Setup

install.packages("leaflet", dependencies = TRUE)
install.packages("leaflet.extras")

install.packages("remotes")
#remotes::install_github('rstudio/flexdashboard')

Features I Love in R

Maps

Geospatial Data is awsome, and most of the times unused.

https://jalcocert.github.io/JAlcocerT/blog/tinker-phyphox/

At some point I was putting together .GPX files with the help of https://www.youtrack.es

But you can do it also with some script.

Put simply, GPX stands for GPS eXchange Format 🌍

And it’s nothing but a simple text file with geographical information, such as latitude, longitude, elevation, time, and so on.

If you plot these points on a map, you’ll know exactly where you need to go, and what sort of terrain you might expect, at least according to the elevation.

You will also hear about GeoJSON format, KML, TopoJSON

Animations

Generally plots in R got me in love: https://r-graph-gallery.com/

FlexDashboards

The cool thing?

We can have leaflet maps, HTML widgets, even animations inside of them.

They can be enhanced with:

  1. https://www.htmlwidgets.org/
install.packages("flexdashboard") #flexdashboard package from CRAN
remotes::install_github('rstudio/flexdashboard') #development version of the package, install it from GitHub via the remotes package

And now render the dashboard:

Rscript -e "rmarkdown::render('z_my_dashboardv2.Rmd')"
python3 -m http.server 8001 #or 8001 if thats taken...
ℹ️
See a sample flexdashboard at RStocks project 💻

FlexDashboard with Github Pages and Github Actions

Github Actions is an awsome and free CI/CD tool to use.

ℹ️
And thse Flexdashboards are having as output a html, feel free to combine them within SSGs!
GH Actions workflow for FlexDashboards to Github Pages 📌
ℹ️
More GHA uses cases, here

Shiny

Shiny I created my very first web app.

In the meantime, there is now Shiny for Python.

ℹ️
See RStocks Project repo for ideas 💻

Containers for Shiny Apps

https://jalcocert.github.io/JAlcocerT/building-r-shiny-apps-container-image-with-docker/