You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/intro_htmlwidgets.Rmd
+29-28Lines changed: 29 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -41,17 +41,16 @@ To create a new widget you can call `scaffoldReactWidget` to generate the basic
41
41
* Create the .R, .js, .yaml, and .json files required by your widget;
42
42
* If provided, take an [npm](https://www.npmjs.com/) package name and version as a named list with `name` and `version` elements. For example, the npm package `foo` at version `^1.2.0` would be expressed as `list(name = "foo", version = "^1.2.0")`. The package, if provided, will be added to the new widget's `package.json` as a build dependency.
43
43
44
-
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:
44
+
The following R code will create an R package named **sparklines**, then provide the templating for creating an htmlwidget powered by the `react-sparklines` npm package:
45
45
46
46
```{r}
47
-
# Set the current working directory to your home directory. The new widget will
48
-
# be created in ~/sparklines
49
-
setwd("~")
50
-
# Create a directory 'sparklines' and populate it with skeletal package
51
-
# If run within RStudio, this will create a new RStudio session
52
-
usethis::create_package("sparklines")
53
-
# Generate skeletal reactR widget code and supporting build configuration
54
-
reactR::scaffoldReactWidget("sparklines", list(name = "react-sparklines", version = "^1.7.0"))
47
+
# Create the R package
48
+
usethis::create_package("~/sparklines")
49
+
# Inject the widget templating
50
+
withr::with_dir(
51
+
"~/sparklines",
52
+
reactR::scaffoldReactWidget("sparklines", list(name = "react-sparklines", version = "^1.7.0"))
53
+
)
55
54
```
56
55
57
56
## Building and installing
@@ -60,9 +59,9 @@ reactR::scaffoldReactWidget("sparklines", list(name = "react-sparklines", versio
60
59
61
60
The next step is to navigate to the newly-created `sparklines` directory in your terminal. Then, run the following commands:
62
61
63
-
```{bash eval = FALSE}
64
-
yarn install
65
-
yarn run webpack
62
+
```{r}
63
+
system("yarn install")
64
+
system("yarn run webpack")
66
65
```
67
66
68
67
*`yarn install` downloads all of the dependencies listed in `package.json` and creates a new file, `yarn.lock`. You should add this file to revision control. It will be updated whenever you change dependencies and run `yarn install`. **Note: you only need to run it after modifying package.json**. For further documentation on `yarn install`, see the [yarn documentation](https://yarnpkg.com/lang/en/docs/cli/install/).
0 commit comments