reactR provides a set of convenience functions for using React in R with htmlwidget constructor templates and local JavaScript dependencies. The React ecosystem is rich with components that can enhance R web and Shiny apps. scaffoldReactWidget() helps build htmlwidgets to integrate these React components as Rhtmlwidgets. The local dependency functions are modeled after the html_dependency_* functions from RStudio’s rmarkdown package.
You can install reactR from CRAN with install.packages("reactR"). For the development version, please use devtools as shown below.
# install.packages("devtools")devtools::install_github("react-R/reactR")To wrap a React component as an htmlwidget, please see the tutorial htmlwidgets with reactR. Also, there are a variety of examples in the react-R Github organization.
Currently, htmlwidgets built with reactR work well in Shiny as outputs. In the next version we hope to have a mechanism for input in Shiny contexts.
library(reactR) library(htmltools) browsable(tagList( tags$div(id="app"), tags$script( " ReactDOM.render( React.createElement( 'h1', null, 'Powered by React' ), document.getElementById('app') )" ), #add core-js first to work in RStudio Viewer html_dependency_corejs(), html_dependency_react() ))reactR uses the V8 package if available to transform JSX and ES2015 code with babel.
library(reactR) library(htmltools) browsable( tagList( tags$div(id="app"), tags$script( babel_transform('ReactDOM.render(<h1>Powered By React/JSX</h1>,document.getElementById("app"))') ), # add core-js shim first for React in RStudio Viewer html_dependency_corejs(), html_dependency_react() ) )We welcome contributors and would love your participation. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by the terms.
We operate a Slack workspace you are more than welcome to join.