Skip to content

Commit 5c2e639

Browse files
authored
Merge branch 'enhancements' into htmlwidgets-vignette
2 parents 9983058 + 9e94c1a commit 5c2e639

File tree

9 files changed

+45
-34
lines changed

9 files changed

+45
-34
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package: reactR
22
Type: Package
33
Title: React Helpers
44
Version: 0.3.0
5-
Date: 2019-01-03
5+
Date: 2019-01-11
66
Authors@R: c(
77
person(
88
"Facebook", "Inc"
@@ -23,8 +23,8 @@ Authors@R: c(
2323
)
2424
)
2525
Maintainer: Kent Russell <[email protected]>
26-
Description: Make it easy to use 'React' in R with helper
27-
dependency functions, embedded 'Babel' 'transpiler',
26+
Description: Make it easy to use 'React' in R with 'htmlwidget' scaffolds,
27+
helper dependency functions, an embedded 'Babel' 'transpiler',
2828
and examples.
2929
URL: https://github.com/react-R/reactR
3030
BugReports: https://github.com/react-R/reactR/issues

R/dependencies.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ html_dependency_corejs <- function() {
7373

7474
#' Adds window.reactR.exposeComponents and window.reactR.hydrate
7575
#'
76-
#' @return
76+
#' @return \code{\link[htmltools]{htmlDependency}}
77+
#' @importFrom htmltools htmlDependency
7778
#' @export
78-
#'
79-
#' @examples
8079
html_dependency_reacttools <- function(){
8180
htmltools::htmlDependency(
8281
name = "reactwidget",

R/reacttools.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ component <- function(name, varArgs = list()) {
2525
if (length(name) == 0 || !isUpper(substring(name, 1, 1))) {
2626
stop("Component name must be specified and start with an upper case character")
2727
}
28-
htmltools::tag(name, varArgs)
28+
component <- htmltools::tag(name, varArgs)
29+
structure(component, class = c("reactR_component", oldClass(component)))
2930
}
3031

3132
#' React component builder.
@@ -76,16 +77,18 @@ React <- structure(
7677
#' Prepare data that represents a single-element character vector, a React
7778
#' component, or an htmltools tag for sending to the client.
7879
#'
80+
#' Tag lists as returned by \code{\link[htmltools]{tagList}} are not currently
81+
#' supported.
82+
#'
7983
#' @param tag character vector or React component or
8084
#' \code{\link[htmltools]{tag}}
8185
#'
82-
#' @return
86+
#' @return A reactR markup object suitable for being passed to
87+
#' \code{\link[htmlwidgets]{createWidget}} as widget instance data.
8388
#' @export
84-
#'
85-
#' @examples
8689
reactMarkup <- function(tag) {
87-
stopifnot(class(tag) == "shiny.tag"
90+
stopifnot(inherits(tag, "shiny.tag")
8891
|| (is.character(tag) && length(tag) == 1))
89-
list(tag = tag, class = "reactR.markup")
92+
list(tag = tag, class = "reactR_markup")
9093
}
9194

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/reactR)](https://cran.r-project.org/package=reactR)
22
[![Travis-CI Build Status](https://travis-ci.org/react-R/reactR.svg?branch=master)](https://travis-ci.org/react-R/reactR)
33

4-
<img height="150px" alt="react-R logo" src="assets/logos/reactR-logo.png"/>
4+
<img height="150px" alt="react-R logo" src="https://github.com/react-R/reactR/raw/enhancements/assets/logos/reactR-logo.png"/>
55

66
# reactR
77

8-
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.
99

1010
## Installation
1111

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.
1313

1414
```R
1515
# install.packages("devtools")
1616
devtools::install_github("react-R/reactR")
1717
```
1818

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
2024

2125
```R
2226
library(reactR)
2327
library(htmltools)
2428

2529
browsable(tagList(
30+
tags$div(id = "app"),
2631
tags$script(
2732
"
2833
ReactDOM.render(
@@ -31,7 +36,7 @@ browsable(tagList(
3136
null,
3237
'Powered by React'
3338
),
34-
document.body
39+
document.getElementById('app')
3540
)
3641
"
3742
),
@@ -41,16 +46,17 @@ browsable(tagList(
4146
))
4247
```
4348

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.
4550

4651
```R
4752
library(reactR)
4853
library(htmltools)
4954

5055
browsable(
5156
tagList(
57+
tags$div(id = "app"),
5258
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"))')
5460
),
5561
# add core-js shim first for React in RStudio Viewer
5662
html_dependency_corejs(),
@@ -61,4 +67,4 @@ browsable(
6167

6268
## Contributing and Code of Conduct
6369

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.

inst/templates/widget_r.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ render${capName} <- function(expr, env = parent.frame(), quoted = FALSE) {
5252
#' Called by HTMLWidgets to produce the widget's root element.
5353
#' @rdname ${name}-shiny
5454
${name}_html <- function(id, style, class, ...) {
55-
tagList(
55+
htmltools::tagList(
5656
# Necessary for RStudio viewer version < 1.2
5757
reactR::html_dependency_corejs(),
5858
reactR::html_dependency_react(),

man/builder.Rd

Lines changed: 0 additions & 9 deletions
This file was deleted.

man/html_dependency_reacttools.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/reactMarkup.Rd

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/intro_htmlwidgets.Rmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ To create a new widget you can call `scaffoldReactWidget` to generate the basic
4444
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:
4545

4646
```{r}
47+
# Set the current working directory to your home directory. The new widget will
48+
# be created in ~/sparklines
49+
setwd("~")
4750
# Create a directory 'sparklines' and populate it with skeletal package
4851
# If run within RStudio, this will create a new RStudio session
4952
usethis::create_package("sparklines")
@@ -120,6 +123,8 @@ data = sampleData,
120123
sparklinesLine(color = "#56b45d"),
121124
sparklinesSpots(style = list(fill = "#56b45d"))
122125
)
126+
=======
127+
reactWidget('reactSparklines', 'output', SparklinesComponents, {});
123128
```
124129

125130
The following sections show how to implement this R interface from our scaffolded widget.

0 commit comments

Comments
 (0)