|
| 1 | +#' Create implementation scaffolding for a React.js-based Shiny input. |
| 2 | +#' |
| 3 | +#' Add the minimal code required to implement a React.js-based Shiny input to an |
| 4 | +#' R package. |
| 5 | +#' |
| 6 | +#' @param name Name of input |
| 7 | +#' @param npmPkgs Optional \href{https://npmjs.com/}{NPM} packages upon which |
| 8 | +#' this input is based which will be used to populate \code{package.json}. |
| 9 | +#' Should be a named list of names to |
| 10 | +#' \href{https://docs.npmjs.com/files/package.json#dependencies}{versions}. |
| 11 | +#' @param edit Automatically open the input's source files after creating the |
| 12 | +#' scaffolding. |
| 13 | +#' |
| 14 | +#' @note This function must be executed from the root directory of the package |
| 15 | +#' you wish to add the input to. |
| 16 | +#' |
| 17 | +#' @export |
| 18 | +scaffoldReactInput <- function(name, npmPkgs = NULL, edit = interactive()) { |
| 19 | + if (!file.exists('DESCRIPTION')){ |
| 20 | + stop( |
| 21 | + "You need to create a package to house your widget first!", |
| 22 | + call. = F |
| 23 | + ) |
| 24 | + } |
| 25 | + |
| 26 | + package <- read.dcf('DESCRIPTION')[[1,"Package"]] |
| 27 | + |
| 28 | + # Add input constructor |
| 29 | + renderFile( |
| 30 | + sprintf("R/%s.R", name), |
| 31 | + "templates/input_r.txt", |
| 32 | + "boilerplate for input constructor", |
| 33 | + list( |
| 34 | + name = name, |
| 35 | + package = package, |
| 36 | + capName = capitalize(name) |
| 37 | + ) |
| 38 | + ) |
| 39 | + # addInputConstructor(name, package, edit) |
| 40 | + # addInputJSON(toDepJSON(npmPkgs)) |
| 41 | + # addWebpackConfig(name) |
| 42 | + # addWidgetJS(name, edit) |
| 43 | + # addExampleApp(name) |
| 44 | + # |
| 45 | + # usethis::use_build_ignore(c("node_modules", "srcjs")) |
| 46 | + # usethis::use_git_ignore(c("node_modules")) |
| 47 | + # lapply(c("htmltools", "htmlwidgets", "reactR"), usethis::use_package) |
| 48 | + # |
| 49 | + # message("To install dependencies from npm run: yarn install") |
| 50 | + # message("To build JavaScript run: yarn run webpack --mode=development") |
| 51 | +} |
| 52 | + |
0 commit comments