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
+67-6Lines changed: 67 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ We'll start by preparing our machine for React and reactR widget development. Th
30
30
31
31
In order to develop a reactR widget, you'll need to install R and optionally RStudio. If you're on Windows, you should also install [Rtools](https://cran.r-project.org/bin/windows/Rtools/).
32
32
33
-
> For an introduction to general R package concepts, please consult the excellent[R packages](http://r-pkgs.had.co.nz/) online book.
33
+
> For an excellent general introduction to R package concepts, check out the [R packages](http://r-pkgs.had.co.nz/) online book.
34
34
35
35
In addition, you'll need to install the following JavaScript tools on your machine:
36
36
@@ -43,8 +43,8 @@ Several packages must be installed to continue. You can install them like this:
43
43
44
44
> QA Note: The necessary version of reactR is not yet available on CRAN. Please install reactR with `devtools::install_github("react-R/reactR@enhancements")`
At this point, the `reactSparklines` contains a bare-bones widget in a package called `reactSparklines`.
71
+
72
+
## Building and installing
73
+
74
+
### Building the JavaScript
75
+
76
+
The next step is to navigate to the `reactSparklines` directory in your terminal. Then, run the following commands:
77
+
78
+
```{shell}
79
+
yarn install
80
+
yarn run webpack --mode=development
81
+
```
82
+
83
+
*`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`. **You only need to run it after modifying package.json**.
84
+
*`yarn run webpack --mode=development` converts the [ES2015](https://babeljs.io/docs/en/learn/) JavaScript source file at `srcjs/reactSparklines.js` into `inst/htmlwidgets/reactSparklines.js`. The difference between the two is that the one in `inst/` bundles all dependencies. It is also compiled in a dialect of JavaScript that will run on a wider variety of old browsers.
85
+
86
+
For further documentation on `yarn install`, see the [yarn documentation](https://yarnpkg.com/lang/en/docs/cli/install/).
87
+
88
+
`yarn run webpack` is not strictly a `yarn` command. In fact, `yarn run` simply delegates to the [webpack](https://webpack.js.org/) program. `development` is one of several [webpack modes](https://webpack.js.org/concepts/#mode). webpack's configuration is generated by `scaffoldReactWidget` in the file `webpack.config.js`.
89
+
90
+
### Building the package
91
+
92
+
While the JavaScript has been built, the `reactSparklines` package has not. Now that the JavaScript asset has been created, we can build it:
93
+
94
+
```{r eval = FALSE}
95
+
devtools::document()
96
+
devtools::install(quick = TRUE)
97
+
```
98
+
99
+
Alternatively, in RStudio, you can use the keyboard shortcuts `Ctrl+Shift+D` and `Ctrl-Shift-B` to document and build the package. (On macOS, the shortcuts are `Cmd+Shift+D` and `Cmd+Shift+B`)
100
+
101
+
## Run example
102
+
103
+
Now that the widget's JavaScript has been compiled and the package has been installed, we can run `app.R` to see the widget in action:
104
+
105
+
```{r eval = FALSE}
106
+
shiny::runApp()
107
+
```
108
+
109
+
Alternatively, in RStudio, you can open `app.R` and press `Ctrl-Shift-Enter` (`Cmd-Shift-Enter` on macOS). You should see something like the following appear in the Viewer pane:
110
+
111
+
```{r echo=FALSE}
112
+
knitr::include_graphics('./widget_app.jpg')
113
+
```
114
+
115
+
## Implement Functionality
116
+
117
+
At this point, we've scaffolded a widget and built its JavaScript, but we have not implemented any functionality provided by the `react-sparklines` library.
118
+
119
+
To expose that functionality through our widget, we must modify the JavaScript in `srcjs/reactSparklines.js`. After scaffolding, it looks like this:
0 commit comments