Skip to content
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

Easy React-based input bindings #22

Merged
merged 63 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
a2d5c0c
WIP createReactInput
alandipert Feb 6, 2019
3cfa77c
Improvements to createReactInput arg list
alandipert Feb 7, 2019
43ca1b8
Merge remote-tracking branch 'origin' into input-binding
alandipert Feb 12, 2019
1617d34
Import input code from test project
alandipert Feb 12, 2019
f356b69
Reorganize JS: split into widget and input files
alandipert Feb 13, 2019
df7d933
Reorganize JS: split into widget and input files
alandipert Feb 13, 2019
ada6743
Reorganize JS: split into widget and input files
alandipert Feb 13, 2019
12108b9
Merge branch 'input-binding' of github.com:react-R/reactR into input-…
alandipert Feb 22, 2019
f1d9963
Refactor scaffold code to prepare for input scaffold
alandipert Feb 22, 2019
3443182
Comment renderFile
alandipert Feb 26, 2019
79e9cf2
Depend formally on jsonlite via Suggests, dep should normally be prov…
alandipert Feb 26, 2019
0315b27
Qualify calls to file.edit and restoreInput to satisfy R CMD check
alandipert Feb 26, 2019
7c63228
Sort, reorganize, fix .Rbuildignore and .gitignore
alandipert Feb 26, 2019
66d5dbb
Complete scaffold refactor
alandipert Feb 26, 2019
1034c77
Small improvements to widgets vignette
alandipert Feb 26, 2019
ec1ee1b
Use development mode in webpack in scaffolded projects
alandipert Feb 26, 2019
523a59b
Bring back fileEdit to open files properly in RStudio
alandipert Feb 26, 2019
972bbe3
Don't show warnings in scaffold when dir.create
alandipert Feb 26, 2019
0a0db7e
Fix .Rbuildignore entry generation in scaffold
alandipert Feb 26, 2019
0c2100b
Bring back usethis::use_build_ignore
alandipert Feb 26, 2019
6c2414c
Remove unnecessary dir.create from widget scaffold
alandipert Feb 26, 2019
6c7940c
WIP input scaffold
alandipert Feb 27, 2019
b48c208
webpack
alandipert Feb 27, 2019
2602d41
Working input scaffold; dedup package.json and webpack templates
alandipert Feb 27, 2019
37a58a8
Fix images in htmlwidgets vignette
alandipert Feb 28, 2019
30f81e5
Add input vignette and screenshots
alandipert Feb 28, 2019
153c4e5
Merge remote-tracking branch 'origin' into input-binding
alandipert Feb 28, 2019
39961bd
Use .jsx extension for scaffolded widget JS
alandipert Mar 4, 2019
a3acd8f
Add newline to widget yaml template
alandipert Mar 4, 2019
4e22489
Workaround mysterious HTMLWidgets scaffold problem related to webpack…
alandipert Mar 4, 2019
a3dbcd2
webpack
alandipert Mar 4, 2019
5f26324
Bring back changes from #18 'add render results to instance' that wer…
alandipert Mar 4, 2019
50a5945
webpack
alandipert Mar 4, 2019
112ebb9
yarn
alandipert Mar 4, 2019
14aee08
Add default update*Input function to input scaffold
alandipert Mar 4, 2019
c750110
add comment in JavaScript saying that component might be null
timelyportfolio Mar 5, 2019
b8a26aa
No need for input scaffold to call restoreInput
alandipert Mar 14, 2019
885c035
Add @example for createReactInput
alandipert Mar 14, 2019
17b8994
Add todos to JS
alandipert Mar 14, 2019
49c065b
reactInput => reactShinyInput
alandipert Mar 14, 2019
9dcd497
webpack
alandipert Mar 14, 2019
361e7d2
scaffoldReactInput => scaffoldReactShinyInput
alandipert Mar 14, 2019
2d36b8f
Constrain names allowed for scaffolded inputs and widgets
alandipert Mar 14, 2019
5f97dfa
createReactInput => createReactShinyInput
alandipert Mar 14, 2019
0e62607
Allow underscores in name regex
alandipert Mar 15, 2019
6262f06
Initialize input value from JSON but maintain it as jQuery data
alandipert Mar 15, 2019
9dfa884
webpack
alandipert Mar 15, 2019
259bc32
Improve getPackage error message
alandipert Mar 15, 2019
70295a1
Merge branch 'input-binding' of github.com:react-R/reactR into input-…
alandipert Mar 15, 2019
2b857df
Improve input vignette slightly
alandipert Mar 15, 2019
3e4563b
webpack
alandipert Mar 15, 2019
eebdfda
Restrict name strings in scaffolding to avoid subsequent problems
alandipert Mar 28, 2019
d11dadb
Add .DS_Store to gitignore
alandipert Mar 28, 2019
7c6065a
In input scaffold, depend on shiny instead of htmlwidgets
alandipert Mar 28, 2019
d82e6f2
Add app.R and assorted JS files to .Rbuildignore in scaffolded projects
alandipert Mar 28, 2019
74514c8
Improve input vignette: fix typos, use video instead of gif
alandipert Mar 28, 2019
e3e5b35
webpack
alandipert Mar 28, 2019
da8986a
inputs: re-order html deps and include corejs for shinytest compat
alandipert Apr 4, 2019
67b880a
Merge branch 'input-binding' of github.com:react-R/reactR into input-…
alandipert Apr 4, 2019
973394e
increment version and update date in DESCRIPTION
timelyportfolio Apr 9, 2019
f91656d
add reactR namespace to createReactShinyInput
timelyportfolio Apr 9, 2019
d6febea
add htmltools namespace to htmlDependency
timelyportfolio Apr 9, 2019
38aca8b
add htmltools namespace to tags$span
timelyportfolio Apr 9, 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
16 changes: 8 additions & 8 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
^pkgdown$
^assets$
^.*\.Rproj$
^\.Rproj\.user$
^\build
^CONDUCT\.md$
^cran-comments\.md$
^docs$
^README\.Rmd$
^\.Rproj\.user$
^\.travis\.yml$
^\assets
^build$
^docs$
^cran-comments\.md$
^karma\.conf\.js$
^logo.svg$
^package\.json$
^webpack\.config\.js$
^yarn\.lock$
^README\.Rmd$
logo.svg
webpack.config.js
^logo\.svg$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Meta
doc
.Rproj.user
.Rhistory
.RData
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Suggests:
shiny,
V8,
knitr,
usethis
usethis,
jsonlite
RoxygenNote: 6.1.1
VignetteBuilder: knitr
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ S3method("[[<-",react_component_builder)
export(React)
export(babel_transform)
export(component)
export(createReactShinyInput)
export(html_dependency_corejs)
export(html_dependency_react)
export(html_dependency_reacttools)
export(reactMarkup)
export(scaffoldReactShinyInput)
export(scaffoldReactWidget)
importFrom(htmltools,htmlDependency)
53 changes: 53 additions & 0 deletions R/reacttools.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,56 @@ reactMarkup <- function(tag) {
list(tag = tag, class = "reactR_markup")
}

#' Create a React-based input
#'
#' @param inputId The \code{input} slot that will be used to access the value.
#' @param class Space-delimited list of CSS class names that should identify
#' this input type in the browser.
#' @param dependencies HTML dependencies to include in addition to those
#' supporting React. Must contain at least one dependency, that of the input's
#' implementation.
#' @param default Initial value.
#' @param configuration Static configuration data.
#' @param container Function to generate an HTML element to contain the input.
#'
#' @return Shiny input suitable for inclusion in a UI.
#' @export
#'
#' @examples
#' myInput <- function(inputId, default = "") {
#' # The value of createReactShinyInput should be returned from input constructor functions.
#' createReactShinyInput(
#' inputId,
#' "myinput",
#' # At least one htmlDependency must be provided -- the JavaScript implementation of the input.
#' htmlDependency(
#' name = "my-input",
#' version = "1.0.0",
#' src = "www/mypackage/myinput",
#' package = "mypackage",
#' script = "myinput.js"
#' ),
#' default
#' )
#' }
createReactShinyInput <- function(inputId,
class,
dependencies,
default = NULL,
configuration = list(),
container = htmltools::tags$div) {
if(length(dependencies) < 1) stop("Must include at least one HTML dependency.")
value <- shiny::restoreInput(id = inputId, default = default)
htmltools::tagList(
container(id = inputId, class = class),
htmltools::tags$script(id = sprintf("%s_value", inputId),
type = "application/json",
jsonlite::toJSON(value, auto_unbox = TRUE)),
htmltools::tags$script(id = sprintf("%s_configuration", inputId),
type = "application/json",
jsonlite::toJSON(configuration, auto_unbox = TRUE)),
html_dependency_react(),
html_dependency_reacttools(),
dependencies
)
}
163 changes: 0 additions & 163 deletions R/scaffold.R

This file was deleted.

78 changes: 78 additions & 0 deletions R/scaffold_input.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#' Create implementation scaffolding for a React.js-based Shiny input.
#'
#' Add the minimal code required to implement a React.js-based Shiny input to an
#' R package.
#'
#' @param name Name of input
#' @param npmPkgs Optional \href{https://npmjs.com/}{NPM} packages upon which
#' this input is based which will be used to populate \code{package.json}.
#' Should be a named list of names to
#' \href{https://docs.npmjs.com/files/package.json#dependencies}{versions}.
#' @param edit Automatically open the input's source files after creating the
#' scaffolding.
#'
#' @note This function must be executed from the root directory of the package
#' you wish to add the input to.
#'
#' @export
scaffoldReactShinyInput <- function(name, npmPkgs = NULL, edit = interactive()) {
assertNameValid(name)
package <- getPackage()

file <- renderFile(
sprintf("R/%s.R", name),
"templates/input_r.txt",
"boilerplate for input constructor",
list(
name = name,
capName = capitalize(name),
package = package
)
)
if (edit) fileEdit(file)

renderFile(
'package.json',
'templates/package.json.txt',
'project metadata',
list(npmPkgs = toDepJSON(npmPkgs))
)

renderFile(
'webpack.config.js',
'templates/webpack.config.js.txt',
'webpack configuration',
list(
name = name,
outputPath = sprintf("inst/www/%s/%s", package, name)
)
)

renderFile(
sprintf('srcjs/%s.jsx', name),
'templates/input_js.txt',
'JavaScript implementation',
list(
name = name,
package = package
)
)

renderFile(
'app.R',
'templates/input_app.R.txt',
'example app',
list(
name = name,
package = package
)
)

usethis::use_build_ignore(c("node_modules", "srcjs"))
usethis::use_git_ignore(c("node_modules"))
lapply(c("htmltools", "htmlwidgets", "reactR"), usethis::use_package)
alandipert marked this conversation as resolved.
Show resolved Hide resolved

message("To install dependencies from npm run: yarn install")
message("To build JavaScript run: yarn run webpack --mode=development")
}

Loading