You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A set of convenience function with local dependencies for using [`React`](https://facebook.github.io/react) in `R`. This is modeled after the `html_dependency_*` functions from RStudio's [`rmarkdown`](https://github.com/rstudio/rmarkdown) package.
8
+
`reactR` provides a set of convenience functions for using [`React`](https://facebook.github.io/react) in `R` with `htmlwidget` constructor templates and local JavaScript dependencies. The `React` ecosystem is rich with comoponents that can enhance `R` web and shiny apps. `scaffoldWidget` helps build `htmlwidgets` to integrate these `React` components as `R``htmlwidgets`. The local dependency functions are modeled after the `html_dependency_*` functions from RStudio's [`rmarkdown`](https://github.com/rstudio/rmarkdown) package.
9
9
10
10
## Installation
11
11
12
-
You can install reactR from github with:
12
+
You can install reactR from CRAN with`install.packages("reactR")`. For the development version, please use `devtools` as shown below.
13
13
14
14
```R
15
15
# install.packages("devtools")
16
16
devtools::install_github("react-R/reactR")
17
17
```
18
18
19
-
## Example
19
+
## Creating htmlwidgets with React Components
20
+
21
+
To wrap a `React` component as an `htmlwidget`, please see the tutorial [htmlwidgets with reactR](https://react-r.github.io/reactR/articles/intro_htmlwidgets.html). Also, there are a variety of examples in the [react-R Github organization](https://github.com/react-R).
22
+
23
+
## Examples
20
24
21
25
```R
22
26
library(reactR)
23
27
library(htmltools)
24
28
25
29
browsable(tagList(
30
+
tags$div(id="app"),
26
31
tags$script(
27
32
"
28
33
ReactDOM.render(
@@ -31,7 +36,7 @@ browsable(tagList(
31
36
null,
32
37
'Powered by React'
33
38
),
34
-
document.body
39
+
document.getElementById('app')
35
40
)
36
41
"
37
42
),
@@ -41,16 +46,17 @@ browsable(tagList(
41
46
))
42
47
```
43
48
44
-
`reactR` also uses `V8` if available to transform `JSX` and `ES2015` code.
49
+
`reactR` also uses the `V8` package if available to transform `JSX` and `ES2015` code.
45
50
46
51
```R
47
52
library(reactR)
48
53
library(htmltools)
49
54
50
55
browsable(
51
56
tagList(
57
+
tags$div(id="app"),
52
58
tags$script(
53
-
babel_transform('ReactDOM.render(<h1>Powered By React/JSX</h1>,document.body)')
59
+
babel_transform('ReactDOM.render(<h1>Powered By React/JSX</h1>,document.getElementById("app"))')
54
60
),
55
61
# add core-js shim first for React in RStudio Viewer
56
62
html_dependency_corejs(),
@@ -61,4 +67,4 @@ browsable(
61
67
62
68
## Contributing and Code of Conduct
63
69
64
-
I welcome contributors. Help make this package great. Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.
70
+
We welcome contributors and would love your participation. Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by the terms.
Copy file name to clipboardExpand all lines: vignettes/intro_htmlwidgets.Rmd
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,9 @@ To create a new widget you can call `scaffoldReactWidget` to generate the basic
44
44
The following R code will create a package named **sparklines**, then provide the templating for creating an htmlwidget powered by the `react-sparklines` npm package:
45
45
46
46
```{r}
47
+
# Set the current working directory to your home directory. The new widget will
48
+
# be created in ~/sparklines
49
+
setwd("~")
47
50
# Create a directory 'sparklines' and populate it with skeletal package
48
51
# If run within RStudio, this will create a new RStudio session
0 commit comments