You are currently browsing the tag archive for the ‘htmlwidgets’ tag.
We quietly introduced this package in December when we announced htmlwidgets, but in the months since then we’ve added a lot of new features and launched a new set of documentation. If you haven’t looked at leaflet lately, now is a great time to get reacquainted!
The Map Widget
The basic usage of this package is that you create a map widget using the
leaflet() function, and add layers to the map using the layer functions such as
addMarkers(), and so on. Adding layers can be done through the pipe operator
%>% from magrittr (you are not required to use
library(leaflet) m <- leaflet() %>% addTiles() %>% # Add default OpenStreetMap map tiles addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R") m # Print the map
There are a variety of layers that you can add to a map widget, including:
- Map tiles
- Markers / Circle Markers
- Polygons / Rectangles
- GeoJSON / TopoJSON
- Raster Images
- Color Legends
- Layer Groups and Layer Control
There are a sets of methods to manipulate the attributes of a map, such as
fitBounds(), etc. You can find the details from the help page
install.packages('DT') # run DT::datatable(iris) to see a "hello world" example
The main function in this package is
datatable(), which returns a table widget that can be rendered in R Markdown documents, Shiny apps, and the R console. It is easy to customize the style (cell borders, row striping, and row highlighting, etc), theme (default or Bootstrap), row/column names, table caption, and so on.
d3heatmap is designed to have a familiar feature set and API for anyone who has used heatmap or heatmap.2 to create static heatmaps. You can specify dendrogram, clustering, and scaling options in the same way.
d3heatmap includes the following features:
- Shows the row/column/value under the mouse cursor
- Click row/column labels to highlight
- Drag a rectangle over the image to zoom in
- Works from the R console, in RStudio, with R Markdown, and with Shiny
Here’s a very simple example (source: flowingdata):
library(d3heatmap) url <- "http://datasets.flowingdata.com/ppg2008.csv" nba_players <- read.csv(url, row.names = 1) d3heatmap(nba_players, scale = "column")
You can easily customize the colors using the
colors parameter. This can take an RColorBrewer palette name, a vector of colors, or a function that takes (potentially scaled) data points as input and returns colors.