-
Notifications
You must be signed in to change notification settings - Fork 37
HTMLWidget and Shiny input integration helpers #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 438ea90
Added sparklines example with README and Windows-compat build
alandipert 0a1ebf3
Add sparklines widget and convert to yarn+webpack-based build
alandipert b8bb5b9
Initial implementation of resize handling
alandipert 43facab
Improve resize handling
alandipert 42e112e
sparklines example: improve README, make tag a span
alandipert 7fcd97c
Simplify renderOnResize functionality and store entire value instead …
alandipert 70d45a2
Hide the shape of the JSON value send to the client behind new reactD…
alandipert a519540
Hydrate arbitrary HTML/SVG tags, still throw an exception if a compon…
alandipert b49a1f4
Remove jQuery dependency from react-tools
alandipert 4f416b0
Add initial impl. of evalJS
alandipert 8738c9b
poc for shiny event handling
timelyportfolio 2d8c765
use shinyEvent instead of shiny and use id prop is available
timelyportfolio eada87b
Merge pull request #5 from timelyportfolio/enhancements-shiny
timelyportfolio 61095b2
Revert "Merge pull request #5 from timelyportfolio/enhancements-shiny"
timelyportfolio 6c22800
Remove evalJS support until we can think of something better
alandipert e177aa0
Build fix attempts
alandipert 3855049
Fix reactR::component example
alandipert 657ac05
update version to 0.3.0 and date
timelyportfolio 32a9467
update React and React-DOM to 16.7.0
timelyportfolio 947ea50
change links and references to react-R org
timelyportfolio f9fba29
Documentation improvements
alandipert 3232e87
Remove examples; moved sparklineswidget to react-R/sparklines
alandipert 9922ad0
Add self as author to DESCRIPTION
alandipert 32b0bea
Added reactR::scaffoldReactWidget for scaffolding output widgets
alandipert 8b39bae
update travis-ci badge to react-R org
timelyportfolio e955fbc
Merge branch 'enhancements' of https://github.com/react-R/reactR into…
timelyportfolio 184e728
Fix minor bug in scaffold template
alandipert 2b96174
Properly handle text nodes and allow htmltools tags
alandipert 8c26d12
Add example app.R during scaffolding
alandipert 0f4c9e6
use `private: true` to avoid missing maintainer warning
schloerke 305cbc7
Make hydrate more robust and add first JS test
alandipert 5f22d0d
Source map support in test failures
alandipert b5bf7d7
Attempt Travis matrix build to run JS in addition to R tests
alandipert 1525747
Merge pull request #6 from schloerke/patch-1
alandipert 7b85242
Specify Node version in Travis config
alandipert 2155d4b
Merge branch 'enhancements' of github.com:react-R/reactR into enhance…
alandipert 79ca0d1
Travis: specify R version
alandipert 2305746
Rename reactData => reactMarkup
alandipert be51515
Rename reactData => reactMarkup
alandipert eb51153
Use new renderTemplate function for scaffold instead of sprintf
alandipert c129486
add logo poc
timelyportfolio 434eecb
make img tag markdown
timelyportfolio 7a68a37
remove quotes from img in README
timelyportfolio 1a0e685
specify height of logo in README
timelyportfolio 167779a
use height attribute in logo on README
timelyportfolio ad8244b
add favicon to docs
timelyportfolio cb9eea0
move logos to /assets and add to Rbuildignore
timelyportfolio b40b356
Add more tests
alandipert 1bd4f09
Merge branch 'enhancements' of github.com:react-R/reactR into enhance…
alandipert 2c95b6f
Minor test re-organization
alandipert 2fe2f84
Fix bug in xmlEqual
alandipert b6d2d24
WIP intro tutorial vignette
alandipert 9b8236e
WIP intro tutorial vignette
alandipert 300823c
Add 4th reactWidget arg to JS template
alandipert 1812397
Further expand htmlwidget intro vignette
alandipert 0102c8f
Complete tutorial
alandipert aa0c195
Ignore JS stuff in .Rbuildignore
alandipert 9cc3310
Add corejs dependency to scaffold so widgets work in RStudio <1.2
alandipert af330c9
Improve R docs
alandipert 5a80783
reactMarkup: error if tag isn't shiny.tag or string
alandipert 68c1f4d
Handle primitive strings as top-level elements in JavaScript
alandipert c37c588
Document defaultOptions
alandipert ab9a66d
Ignore R CMD check related things in dir
alandipert ca7b313
Fix typo in tutorial
alandipert c31d721
Minor tutorial improvement
alandipert e0f62a6
Small enhancements suggested by @cpsievert
alandipert 1808e9d
reactMarkup: return list with class reactR_markup instead of reactR.m…
alandipert ad28dc9
Various documentation additions, enhancements
alandipert 9983058
Make vignette more geared towards an R user that wants to quickly lea…
cpsievert 582bb4a
update date and add mention of htmlwdiget in DESCRIPTION
timelyportfolio 8174f4d
add some discussion on new htmlwidget functionality in README
timelyportfolio 9e94c1a
add htmltools:: to taglist in _html function in R template
timelyportfolio 5c2e639
Merge branch 'enhancements' into htmlwidgets-vignette
alandipert 9659531
Merge pull request #7 from cpsievert/htmlwidgets-vignette
alandipert a513900
Fix intro vignette frontmatter syntax
alandipert f5fff43
npmPkg: Use a named list instead of a char vector
alandipert e66b71d
Tutorial vignette: light editing and formatting
alandipert e519b6d
Minor README edits
alandipert ed5b725
Remove QA note from tutorial vignette
alandipert b7f83dd
Minor vignette edit
alandipert 25a2d9c
spark-lines => react-sparklines
alandipert 02cac39
Credit @cpsievert in tutorial
alandipert c439aa9
pkgdown
timelyportfolio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ^sparklineswidget\.Rproj$ | ||
| ^\.Rproj\.user$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .Rproj.user | ||
| .Rhistory | ||
| .RData | ||
| build/ | ||
| node_modules/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.