Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
961e696
reacttools: Added R constructor and JS runtime, comments.
alandipert Dec 12, 2018
438ea90
Added sparklines example with README and Windows-compat build
alandipert Dec 13, 2018
0a1ebf3
Add sparklines widget and convert to yarn+webpack-based build
alandipert Dec 14, 2018
b8bb5b9
Initial implementation of resize handling
alandipert Dec 18, 2018
43facab
Improve resize handling
alandipert Dec 19, 2018
42e112e
sparklines example: improve README, make tag a span
alandipert Dec 19, 2018
7fcd97c
Simplify renderOnResize functionality and store entire value instead …
alandipert Dec 19, 2018
70d45a2
Hide the shape of the JSON value send to the client behind new reactD…
alandipert Dec 19, 2018
a519540
Hydrate arbitrary HTML/SVG tags, still throw an exception if a compon…
alandipert Dec 19, 2018
b49a1f4
Remove jQuery dependency from react-tools
alandipert Dec 20, 2018
4f416b0
Add initial impl. of evalJS
alandipert Dec 20, 2018
8738c9b
poc for shiny event handling
timelyportfolio Dec 30, 2018
2d8c765
use shinyEvent instead of shiny and use id prop is available
timelyportfolio Dec 31, 2018
eada87b
Merge pull request #5 from timelyportfolio/enhancements-shiny
timelyportfolio Dec 31, 2018
61095b2
Revert "Merge pull request #5 from timelyportfolio/enhancements-shiny"
timelyportfolio Jan 3, 2019
6c22800
Remove evalJS support until we can think of something better
alandipert Jan 3, 2019
e177aa0
Build fix attempts
alandipert Jan 3, 2019
3855049
Fix reactR::component example
alandipert Jan 3, 2019
657ac05
update version to 0.3.0 and date
timelyportfolio Jan 4, 2019
32a9467
update React and React-DOM to 16.7.0
timelyportfolio Jan 4, 2019
947ea50
change links and references to react-R org
timelyportfolio Jan 4, 2019
f9fba29
Documentation improvements
alandipert Jan 4, 2019
3232e87
Remove examples; moved sparklineswidget to react-R/sparklines
alandipert Jan 4, 2019
9922ad0
Add self as author to DESCRIPTION
alandipert Jan 4, 2019
32b0bea
Added reactR::scaffoldReactWidget for scaffolding output widgets
alandipert Jan 5, 2019
8b39bae
update travis-ci badge to react-R org
timelyportfolio Jan 5, 2019
e955fbc
Merge branch 'enhancements' of https://github.com/react-R/reactR into…
timelyportfolio Jan 5, 2019
184e728
Fix minor bug in scaffold template
alandipert Jan 7, 2019
2b96174
Properly handle text nodes and allow htmltools tags
alandipert Jan 7, 2019
8c26d12
Add example app.R during scaffolding
alandipert Jan 7, 2019
0f4c9e6
use `private: true` to avoid missing maintainer warning
schloerke Jan 7, 2019
305cbc7
Make hydrate more robust and add first JS test
alandipert Jan 7, 2019
5f22d0d
Source map support in test failures
alandipert Jan 8, 2019
b5bf7d7
Attempt Travis matrix build to run JS in addition to R tests
alandipert Jan 8, 2019
1525747
Merge pull request #6 from schloerke/patch-1
alandipert Jan 8, 2019
7b85242
Specify Node version in Travis config
alandipert Jan 8, 2019
2155d4b
Merge branch 'enhancements' of github.com:react-R/reactR into enhance…
alandipert Jan 8, 2019
79ca0d1
Travis: specify R version
alandipert Jan 8, 2019
2305746
Rename reactData => reactMarkup
alandipert Jan 9, 2019
be51515
Rename reactData => reactMarkup
alandipert Jan 9, 2019
eb51153
Use new renderTemplate function for scaffold instead of sprintf
alandipert Jan 9, 2019
c129486
add logo poc
timelyportfolio Jan 10, 2019
434eecb
make img tag markdown
timelyportfolio Jan 10, 2019
7a68a37
remove quotes from img in README
timelyportfolio Jan 10, 2019
1a0e685
specify height of logo in README
timelyportfolio Jan 10, 2019
167779a
use height attribute in logo on README
timelyportfolio Jan 10, 2019
ad8244b
add favicon to docs
timelyportfolio Jan 10, 2019
cb9eea0
move logos to /assets and add to Rbuildignore
timelyportfolio Jan 10, 2019
b40b356
Add more tests
alandipert Jan 10, 2019
1bd4f09
Merge branch 'enhancements' of github.com:react-R/reactR into enhance…
alandipert Jan 10, 2019
2c95b6f
Minor test re-organization
alandipert Jan 10, 2019
2fe2f84
Fix bug in xmlEqual
alandipert Jan 10, 2019
b6d2d24
WIP intro tutorial vignette
alandipert Jan 10, 2019
9b8236e
WIP intro tutorial vignette
alandipert Jan 11, 2019
300823c
Add 4th reactWidget arg to JS template
alandipert Jan 11, 2019
1812397
Further expand htmlwidget intro vignette
alandipert Jan 11, 2019
0102c8f
Complete tutorial
alandipert Jan 11, 2019
aa0c195
Ignore JS stuff in .Rbuildignore
alandipert Jan 11, 2019
9cc3310
Add corejs dependency to scaffold so widgets work in RStudio <1.2
alandipert Jan 11, 2019
af330c9
Improve R docs
alandipert Jan 11, 2019
5a80783
reactMarkup: error if tag isn't shiny.tag or string
alandipert Jan 11, 2019
68c1f4d
Handle primitive strings as top-level elements in JavaScript
alandipert Jan 11, 2019
c37c588
Document defaultOptions
alandipert Jan 11, 2019
ab9a66d
Ignore R CMD check related things in dir
alandipert Jan 11, 2019
ca7b313
Fix typo in tutorial
alandipert Jan 11, 2019
c31d721
Minor tutorial improvement
alandipert Jan 11, 2019
e0f62a6
Small enhancements suggested by @cpsievert
alandipert Jan 11, 2019
1808e9d
reactMarkup: return list with class reactR_markup instead of reactR.m…
alandipert Jan 11, 2019
ad28dc9
Various documentation additions, enhancements
alandipert Jan 11, 2019
9983058
Make vignette more geared towards an R user that wants to quickly lea…
cpsievert Jan 12, 2019
582bb4a
update date and add mention of htmlwdiget in DESCRIPTION
timelyportfolio Jan 12, 2019
8174f4d
add some discussion on new htmlwidget functionality in README
timelyportfolio Jan 12, 2019
9e94c1a
add htmltools:: to taglist in _html function in R template
timelyportfolio Jan 12, 2019
5c2e639
Merge branch 'enhancements' into htmlwidgets-vignette
alandipert Jan 12, 2019
9659531
Merge pull request #7 from cpsievert/htmlwidgets-vignette
alandipert Jan 12, 2019
a513900
Fix intro vignette frontmatter syntax
alandipert Jan 12, 2019
f5fff43
npmPkg: Use a named list instead of a char vector
alandipert Jan 12, 2019
e66b71d
Tutorial vignette: light editing and formatting
alandipert Jan 12, 2019
e519b6d
Minor README edits
alandipert Jan 12, 2019
ed5b725
Remove QA note from tutorial vignette
alandipert Jan 12, 2019
b7f83dd
Minor vignette edit
alandipert Jan 12, 2019
25a2d9c
spark-lines => react-sparklines
alandipert Jan 12, 2019
02cac39
Credit @cpsievert in tutorial
alandipert Jan 12, 2019
c439aa9
pkgdown
timelyportfolio Jan 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ URL: https://github.com/timelyportfolio/reactR
BugReports: https://github.com/timelyportfolio/reactR/issues
License: MIT + file LICENSE
LazyData: TRUE
Encoding: UTF-8
Imports:
htmltools
Suggests:
Expand All @@ -32,5 +33,5 @@ Suggests:
shiny,
V8,
knitr
RoxygenNote: 6.0.1
RoxygenNote: 6.1.1
VignetteBuilder: knitr
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Generated by roxygen2: do not edit by hand

S3method("$",react_component_builder)
S3method("$<-",react_component_builder)
S3method("[[",react_component_builder)
S3method("[[<-",react_component_builder)
export(React)
export(babel_transform)
export(component)
export(html_dependency_corejs)
export(html_dependency_react)
export(html_dependency_reacttools)
importFrom(htmltools,htmlDependency)
16 changes: 16 additions & 0 deletions R/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,19 @@ html_dependency_corejs <- function() {
script = "shim.min.js"
)
}

#' Adds window.reactR.exposeComponents and window.reactR.hydrate
#'
#' @return
#' @export
#'
#' @examples
html_dependency_reacttools <- function(){
htmltools::htmlDependency(
name = "reactwidget",
src = "www/react-tools",
version = "1.0.0",
package = "reactR",
script = c("react-tools.js")
)
}
46 changes: 46 additions & 0 deletions R/reacttools.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
isUpper <- function(s) {
grepl("^[[:upper:]]+$", s)
}

#' Create a React component
#'
#' @param name Name of the React component, which must start with an upper-case character.
#' @param ... Attributes and children of the element to pass along to \code{\link[htmltools]{tag}} as varArgs.
#'
#' @return An htmltools \code{\link[htmltools]{tag}} object
#' @export
#'
#' @examples
#' component("ParentComponent",
#' x = 1,
#' y = 2,
#' component("ChildComponent"),
#' component("OtherChildComponent")
#' )
component <- function(name, varArgs = list()) {
if (length(name) == 0 || !isUpper(substring(name, 1, 1))) {
stop("Component name must be specified and start with an upper case character")
}
htmltools::tag(name, varArgs)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add a class or a subclass here? As a package author, I might want to know if a user is supplying a component versus a tag


#' @export
React <- structure(list(), class = "react_component_builder")

#' @export
`$.react_component_builder` <- function(x, name) {
function(...) {
component(name, list(...))
}
}

#' @export
`[[.react_component_builder` <- `$.react_component_builder`

#' @export
`$<-.react_component_builder` <- function(x, name, value) {
stop("Assigning to a component constructor is not allowed")
}

#' @export
`[[<-.react_component_builder` <- `$<-.react_component_builder`
2 changes: 2 additions & 0 deletions examples/sparklineswidget/.Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^sparklineswidget\.Rproj$
^\.Rproj\.user$
5 changes: 5 additions & 0 deletions examples/sparklineswidget/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
build/
node_modules/
16 changes: 16 additions & 0 deletions examples/sparklineswidget/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "yarn run webpack --mode=development",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
12 changes: 12 additions & 0 deletions examples/sparklineswidget/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Package: sparklineswidget
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "[email protected]", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.5.1)
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
Imports:
reactR
9 changes: 9 additions & 0 deletions examples/sparklineswidget/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Generated by roxygen2: do not edit by hand

export(curve)
export(reference_line)
export(renderSparklineswidget)
export(sparklineswidget)
export(sparklineswidgetOutput)
export(spots)
import(htmlwidgets)
70 changes: 70 additions & 0 deletions examples/sparklineswidget/R/sparklineswidget.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#' @export
curve <- function(...) {
reactR::React$SparklinesCurve(...)
}

#' @export
spots <- function(...) {
reactR::React$SparklinesSpots(...)
}

#' @export
reference_line <- function(...) {
reactR::React$SparklinesReferenceLine(...)
}

#' <Add Title>
#'
#' <Add Description>
#'
#' @import htmlwidgets
#'
#' @export
sparklineswidget <- function(data, ...) {
htmlwidgets::createWidget(
name = 'sparklineswidget',
list(tag = reactR::component("Sparklines", c(list(data = data, ...)))),
width = NULL,
height = NULL,
package = 'sparklineswidget',
elementId = NULL
)
}

#' Shiny bindings for sparklineswidget
#'
#' Output and render functions for using sparklineswidget within Shiny
#' applications and interactive Rmd documents.
#'
#' @param outputId output variable to read from
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
#' string and have \code{'px'} appended.
#' @param expr An expression that generates a sparklineswidget
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#'
#' @name sparklineswidget-shiny
#'
#' @export
sparklineswidgetOutput <- function(outputId, width = '100%', height = '400px'){
htmlwidgets::shinyWidgetOutput(outputId, 'sparklineswidget', width, height, package = 'sparklineswidget')
}

#' @rdname sparklineswidget-shiny
#' @export
renderSparklineswidget <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
htmlwidgets::shinyRenderWidget(expr, sparklineswidgetOutput, env, quoted = TRUE)
}

# Magical
sparklineswidget_html <- function(id, style, class, ...) {
tagList(
reactR::html_dependency_corejs(),
reactR::html_dependency_react(),
reactR::html_dependency_reacttools(),
tags$div(id = id, class = class)
)
}
43 changes: 43 additions & 0 deletions examples/sparklineswidget/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# react-sparklines HTMLWidget

This example demonstrates creating an [htmlwidget](https://www.htmlwidgets.org/) wrapper around the [react-sparklines](http://borisyankov.github.io/react-sparklines/) library.

# Building

Because this package includes Javascript source code that requires a compilation step, package installation is in two phases: Javascript tools build the Javascript, and R tools build and install the package. The R package includes the built Javascript files in the `inst/` directory.

## Javascript Build Requirements

Building Javascript should work on macOS, Linux, and Windows. The following tools are necessary regardless of your platform:

- [Node.js](https://nodejs.org/en/)
- [Yarn](https://yarnpkg.com/en/)

## R Build Requirements

You should install the parent `reactR` package if you haven't, as this widget depends on it.

## Development Workflow

After you've installed Node.js and Yarn, run the following command to resolve and download dependencies:

```
yarn install
```

Now, run `yarn` to build `inst/htmlwidgets/sparklineswidget.js`:

```
yarn run webpack --mode=development
```

> To run `yarn webpack` automatically whenever sources change, use the command `yarn run webpack --mode=development --watch`

Now that the Javascript is built, you can install the R package:

```
devtools::document()
devtools::install()
```

Finally you can try the example app by running [app.R](app.R).
33 changes: 33 additions & 0 deletions examples/sparklineswidget/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
library(shiny)
library(sparklineswidget)
library(colourpicker)
# devtools::install_github("hadley/shinySignals")
library(shinySignals)

ui <- fluidPage(
titlePanel("React Sparklines"),
sparklineswidgetOutput('sparklines'),
colourInput("color_curve", "Curve color", "#253e56"),
colourInput("color_spots", "Spots color", "#56b45d")
)

nextWindow <- function(prev = round(runif(100, 0, 10)), t = NULL) {
c(prev[-1], round(runif(1, 0, 10)))
}

server <- function(input, output, session) {

data <- reducePast(fps(1), nextWindow, nextWindow())

output$sparklines <- renderSparklineswidget(
sparklineswidget(data = data(),
curve(color = input$color_curve),
spots(style = list(fill = input$color_spots)),
reference_line(type = "avg")
)
)
}

options(shiny.port = 4343)

shinyApp(ui, server)
Loading