Skip to content

Commit f735449

Browse files
committed
update readme
1 parent dc2bdd6 commit f735449

File tree

1 file changed

+132
-124
lines changed

1 file changed

+132
-124
lines changed

README.Rmd

Lines changed: 132 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,132 @@
1-
---
2-
title: "Add more interactivity to interactive charts"
3-
output: github_document
4-
---
5-
6-
```{r setup, include=FALSE}
7-
knitr::opts_chunk$set(echo = TRUE)
8-
library(manipulateWidget)
9-
```
10-
11-
12-
[![CRAN Status Badge](http://www.r-pkg.org/badges/version/manipulateWidget)](http://cran.r-project.org/package=manipulateWidget)
13-
[![CRAN Downloads Badge](https://cranlogs.r-pkg.org/badges/manipulateWidget)](http://cran.r-project.org/package=manipulateWidget)
14-
[![Travis-CI Build Status](https://travis-ci.org/rte-antares-rpackage/manipulateWidget.svg?branch=master)](https://travis-ci.org/rte-antares-rpackage/manipulateWidget)
15-
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/6y3tdofl0nk7oc4g/branch/master?svg=true)](https://ci.appveyor.com/project/rte-antares-rpackage/manipulatewidget/branch/master)
16-
17-
`manipulateWidget` lets you create in just a few lines of R code a nice user interface to modify the data or the graphical parameters of one or multiple interactive charts. It is useful to quickly explore visually some data or for package developers to generate user interfaces easy to maintain.
18-
19-
![Combining widgets and some html content](vignettes/fancy-example.gif)
20-
21-
This R package is largely inspired by the `manipulate` package from Rstudio. It provides the function `manipulateWidget` that can be used to create in a very easy way a graphical interface that let the user modify the data or the parameters of an interactive chart. Technically, the function generates a Shiny gadget, but the user does not even have to know what is Shiny.
22-
23-
## Why should you use it?
24-
25-
All functionalities of this package can be replicated with other packages like [shiny](https://shiny.rstudio.com/), [flexdashboard](http://rmarkdown.rstudio.com/flexdashboard/), [crosstalk](http://rstudio.github.io/crosstalk/) and others. So why another package?
26-
27-
`manipulateWidget` has three advantages:
28-
29-
* It is easy and fast to use. Only a few lines of `R` are necessary to create a user interface.
30-
* Code can be included in any R script. No need to create a dedicated .R or .Rmd file.
31-
* It works with all htmlwidgets. In contrast, `crosstalk` only supports a few of them.
32-
33-
`manipulateWidget` can be especially powerful for users who are exploring some data set and want to quickly build a graphical tool to see what is in their data. `manipulateWidget` has also some advanced features that can be used with almost no additional code and that could seduce some package developers: grouping inputs, conditional inputs and comparison mode.
34-
35-
36-
## Installation
37-
38-
The package can be installed from CRAN:
39-
40-
```{r eval=FALSE}
41-
install.packages("manipulateWidget")
42-
```
43-
44-
You can also install the latest development version from github:
45-
46-
```{r eval=FALSE}
47-
devtools::install_github("rte-antares-rpackage/manipulateWidget", ref="develop")
48-
```
49-
50-
51-
## Getting started
52-
53-
The hard part for the user is to write a code that generates an interactive chart. Once this is
54-
done, he only has to describe what parameter of the code should be modified by what input control. For instance, consider the following code that identifies clusters in the iris data set and uses package `plotly` to generate an interactive scatter plot.
55-
56-
```{r kmeans, message=FALSE, out.width=600, out.height=400}
57-
library(plotly)
58-
data(iris)
59-
60-
plotClusters <- function(xvar, yvar, nclusters) {
61-
clusters <- kmeans(iris[, 1:4], centers = nclusters)
62-
clusters <- paste("Cluster", clusters$cluster)
63-
64-
plot_ly(x = ~iris[[xvar]], y = ~iris[[yvar]], color = ~clusters,
65-
type = "scatter", mode = "markers") %>%
66-
layout(xaxis = list(title=xvar), yaxis = list(title=yvar))
67-
}
68-
69-
plotClusters("Sepal.Width", "Sepal.Length", 3)
70-
```
71-
72-
Once this code has been written, it is very easy to produce a UI that lets the user change the values of the three parameters of the function `plotClusters`:
73-
74-
```{r eval = FALSE}
75-
varNames <- names(iris)[1:4]
76-
77-
manipulateWidget(
78-
plotClusters(xvar, yvar, nclusters),
79-
xvar = mwSelect(varNames),
80-
yvar = mwSelect(varNames, value = "Sepal.Width"),
81-
nclusters = mwSlider(1, 10, value = 3)
82-
)
83-
```
84-
85-
86-
![An example of output of manipulateWidget](vignettes/example-kmeans.gif)
87-
88-
The package also provides the `combineWidgets` function to easily combine multiple interactive charts in a single view. Of course both functions can be used together. Here is the code to generate the UI in the first animation.
89-
90-
```{r eval = FALSE}
91-
myPlotFun <- function(distribution, range, title) {
92-
randomFun <- switch(distribution, gaussian = rnorm, uniform = runif)
93-
myData <- data.frame(
94-
year = seq(range[1], range[2]),
95-
value = randomFun(n = diff(range) + 1)
96-
)
97-
combineWidgets(
98-
ncol = 1, rowsize = c(2, 1),
99-
dygraph(myData, main = title),
100-
combineWidgets(
101-
ncol = 2,
102-
plot_ly(x = myData$value, type = "histogram"),
103-
paste(
104-
"The graph above represents a random time series generated using a <b>",
105-
distribution, "</b>distribution function.<br/>",
106-
"The chart on the left represents the empirical distribution of the generated values."
107-
)
108-
)
109-
)
110-
111-
}
112-
113-
manipulateWidget(
114-
myPlotFun(distribution, range, title),
115-
distribution = mwSelect(choices = c("gaussian", "uniform")),
116-
range = mwSlider(2000, 2100, value = c(2000, 2100), label = "period"),
117-
title = mwText()
118-
)
119-
120-
```
121-
122-
123-
124-
For more information take a look at the [package vignette](https://cran.r-project.org/web/packages/manipulateWidget/vignettes/manipulateWidgets.html).
1+
---
2+
title: "Add more interactivity to interactive charts"
3+
output: github_document
4+
---
5+
6+
```{r setup, include=FALSE}
7+
knitr::opts_chunk$set(echo = TRUE)
8+
library(manipulateWidget)
9+
```
10+
11+
12+
[![CRAN Status Badge](http://www.r-pkg.org/badges/version/manipulateWidget)](http://cran.r-project.org/package=manipulateWidget)
13+
[![CRAN Downloads Badge](https://cranlogs.r-pkg.org/badges/manipulateWidget)](http://cran.r-project.org/package=manipulateWidget)
14+
[![Travis-CI Build Status](https://travis-ci.org/rte-antares-rpackage/manipulateWidget.svg?branch=master)](https://travis-ci.org/rte-antares-rpackage/manipulateWidget)
15+
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/6y3tdofl0nk7oc4g/branch/master?svg=true)](https://ci.appveyor.com/project/rte-antares-rpackage/manipulatewidget/branch/master)
16+
17+
`manipulateWidget` lets you create in just a few lines of R code a nice user interface to modify the data or the graphical parameters of one or multiple interactive charts. It is useful to quickly explore visually some data or for package developers to generate user interfaces easy to maintain.
18+
19+
![Combining widgets and some html content](vignettes/fancy-example.gif)
20+
21+
This R package is largely inspired by the `manipulate` package from Rstudio. It provides the function `manipulateWidget` that can be used to create in a very easy way a graphical interface that let the user modify the data or the parameters of an interactive chart. Technically, the function generates a Shiny gadget, but the user does not even have to know what is Shiny.
22+
23+
## Why should you use it?
24+
25+
All functionalities of this package can be replicated with other packages like [shiny](https://shiny.rstudio.com/), [flexdashboard](http://rmarkdown.rstudio.com/flexdashboard/), [crosstalk](http://rstudio.github.io/crosstalk/) and others. So why another package?
26+
27+
`manipulateWidget` has three advantages:
28+
29+
* It is easy and fast to use. Only a few lines of `R` are necessary to create a user interface.
30+
* Code can be included in any R script. No need to create a dedicated .R or .Rmd file.
31+
* It works with all htmlwidgets. In contrast, `crosstalk` only supports a few of them.
32+
33+
`manipulateWidget` can be especially powerful for users who are exploring some data set and want to quickly build a graphical tool to see what is in their data. `manipulateWidget` has also some advanced features that can be used with almost no additional code and that could seduce some package developers: grouping inputs, conditional inputs and comparison mode.
34+
35+
36+
## Installation
37+
38+
The package can be installed from CRAN:
39+
40+
```{r eval=FALSE}
41+
install.packages("manipulateWidget")
42+
```
43+
44+
You can also install the latest development version from github:
45+
46+
```{r eval=FALSE}
47+
devtools::install_github("rte-antares-rpackage/manipulateWidget", ref="develop")
48+
```
49+
50+
51+
## Getting started
52+
53+
The hard part for the user is to write a code that generates an interactive chart. Once this is
54+
done, he only has to describe what parameter of the code should be modified by what input control. For instance, consider the following code that identifies clusters in the iris data set and uses package `plotly` to generate an interactive scatter plot.
55+
56+
```{r kmeans, message=FALSE, out.width=600, out.height=400}
57+
library(plotly)
58+
data(iris)
59+
60+
plotClusters <- function(xvar, yvar, nclusters) {
61+
clusters <- kmeans(iris[, 1:4], centers = nclusters)
62+
clusters <- paste("Cluster", clusters$cluster)
63+
64+
plot_ly(x = ~iris[[xvar]], y = ~iris[[yvar]], color = ~clusters,
65+
type = "scatter", mode = "markers") %>%
66+
layout(xaxis = list(title=xvar), yaxis = list(title=yvar))
67+
}
68+
69+
plotClusters("Sepal.Width", "Sepal.Length", 3)
70+
```
71+
72+
Once this code has been written, it is very easy to produce a UI that lets the user change the values of the three parameters of the function `plotClusters`:
73+
74+
```{r eval = FALSE}
75+
varNames <- names(iris)[1:4]
76+
77+
manipulateWidget(
78+
plotClusters(xvar, yvar, nclusters),
79+
xvar = mwSelect(varNames),
80+
yvar = mwSelect(varNames, value = "Sepal.Width"),
81+
nclusters = mwSlider(1, 10, value = 3)
82+
)
83+
```
84+
85+
86+
![An example of output of manipulateWidget](vignettes/example-kmeans.gif)
87+
88+
The package also provides the `combineWidgets` function to easily combine multiple interactive charts in a single view. Of course both functions can be used together. Here is the code to generate the UI in the first animation.
89+
90+
```{r eval = FALSE}
91+
myPlotFun <- function(distribution, range, title) {
92+
randomFun <- switch(distribution, gaussian = rnorm, uniform = runif)
93+
myData <- data.frame(
94+
year = seq(range[1], range[2]),
95+
value = randomFun(n = diff(range) + 1)
96+
)
97+
combineWidgets(
98+
ncol = 1, rowsize = c(2, 1),
99+
dygraph(myData, main = title),
100+
combineWidgets(
101+
ncol = 2,
102+
plot_ly(x = myData$value, type = "histogram"),
103+
paste(
104+
"The graph above represents a random time series generated using a <b>",
105+
distribution, "</b>distribution function.<br/>",
106+
"The chart on the left represents the empirical distribution of the generated values."
107+
)
108+
)
109+
)
110+
111+
}
112+
113+
manipulateWidget(
114+
myPlotFun(distribution, range, title),
115+
distribution = mwSelect(choices = c("gaussian", "uniform")),
116+
range = mwSlider(2000, 2100, value = c(2000, 2100), label = "period"),
117+
title = mwText()
118+
)
119+
120+
```
121+
122+
123+
124+
For more information take a look at the [package vignette](https://cran.r-project.org/web/packages/manipulateWidget/vignettes/manipulateWidgets.html).
125+
126+
## License Information:
127+
128+
Copyright 2015-2016 RTE (France)
129+
130+
* RTE: http://www.rte-france.com
131+
132+
This Source Code is subject to the terms of the GNU General Public License, version 2 or any higher version. If a copy of the GPL-v2 was not distributed with this file, You can obtain one at https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html.

0 commit comments

Comments
 (0)