library(shiny)
textInput("name", "What is your name?")numericInput("age", "How old are you?", NA, min = 0, max = 150)The manipulate package creates a quick interactive graphic that offers simple controls, including sliders, pickers and checkboxes.
library(manipulate)
manipulate(plot(1:x), x = slider(1, 100))With manipulate you can have more than one set of controls by simply adding more arguments to the manipulate function.
Note that it’s difficult to share a manipulate interactive graphic.
This is a link on how manipulate actually works: link
It is described by RStudio as “A web application framework for R”. “Turn your analyses into interactive web applications No HTML, CSS, or JavaScript knowledge required”.
Only those who have shiny installed and have access to your code could run your web page. However, RStudio offers a service for hosting shiny apps (their servers) on a platform called shinyapps.io.
If on Windows, make sure that you have Rtools installed. Then, you can install shiny with library(shiny):
Example:
library(shiny)
textInput("name", "What is your name?")numericInput("age", "How old are you?", NA, min = 0, max = 150)A shiny app consists of two files. First, a file called ui.R that controls the User Interface (hence the ui in the filename) and secondly, a file server.R that controls the shiny server (hence the server in the filename).
library(shiny)
shinyUI(
pageWithSidebar(
headerPanel("Hello Shiny!"),
sidebarPanel(
h3('Sidebar text')
),
mainPanel(
h3('Main Panel text')
)
)
)library(shiny)
shinyServer(
function(input, output) {
}
)The current version of Rstudio has a “Run app” button in the upper right hand corner of the editor if a ui.R or server.R file is open.
To get used to programming shiny apps, you need to throw away a little of your thinking about R; it’s a different style of programming.
Numeric input:
numericInput('id1', 'Numeric input, labeled id1', 0, min = 0, max = 10, step= 1)Checkbox input:
checkboxGroupInput("id2", "Checkbox", c("Value 1" = "1", "Value 2" = "2", "Value 3" = "3"))Date input:
dateInput("date", "Date:")Check out this link
Slidify is for building reproducible presentations.
install.packages("devtools")
library(devtools)/ require(devtools)
install_github('ramnathv/slidify')
install_github('ramnathv'/'slidifyLibraries') o devtools::install_github(pkgs, force = TRUE)
library(slidify)For more information about R studio presenter, chek out this link
Tip: if you’re sort of a hacker type and you like to tinker with things, use slidify. If you just want to get it done and not worry about it, use RPres. Either way, you really can’t go wrong.
HTML is an interactive format, and you can take advantage of that interactivity with htmlwidgets, R functions that produce interactive HTML visualizations. For example, take the leaflet map below, where you can drag the map around, zoom in and out, etc. You obviously can’t do that in a book, so Quarto automatically inserts a static screenshot for you.
Example:
library(leaflet)
leaflet() |>
setView(-3.7077, 40.4156, , zoom = 16) |>
addTiles() |>
addMarkers(-3.7077, 40.4156, popup = "Plaza Mayor de Madrid") There are many packages that provide htmlwidgets, including:
dygraphs for interactive time series visualizations.
DT for interactive tables.
threejs for interactive 3d plots.
DiagrammeR for diagrams (like flow charts and simple node-link diagrams).
To see a complete list of the packages that provide htmlwidgets visit https://www.htmlwidgets.org.
leaflet seems to be emerging as the most popular R package for creating interactive maps.
The map widget (the leaflet() command) starts out a map and then you add elements or modify the map by passing it as arguments to mapping functions.
rCharts is a way to create interactive javascript visualizations using R.
require(devtools)
install_github('rCharts', 'ramnathv')Google has some nice visualization tools built into their products (e.g. Google Maps). These include maps and interactive graphs.
install.packages("googleVis")
library(googlevis)plotly relies on the platform/website plot.ly for creating interactive graphics.
require(devtools)
install_github("ropensci/plotly")Plotly will give you the json data and gives a tremendous number of options for publishing the graph.
Notably, plotly allows for integration with ggplot2.
For interactive graphics, learning some javascript and following that up with D3 would be the logical next step