forked from davidgohel/ggiraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshiny_usage.Rmd
81 lines (54 loc) · 2.21 KB
/
shiny_usage.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
title: "ggiraph in shiny"
output:
rmarkdown::html_vignette:
toc: true
toc_depth: 2
vignette: >
%\VignetteIndexEntry{ggiraph in shiny}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
`ggiraph` is an htmlwidget. It can be used within a Shiny application. In shiny, elements associated with `data_id` can be selected and the selection (the `data_id` value) is available in the client and the server side of the application.
## The client `ui.R`
Instead of a `plotOutput`, use function `ggiraphOutput`.
```{r eval=FALSE}
ggiraphOutput("plot")
```
## The server `server.R`
Use function `ggiraphOutput`.
```{r eval=FALSE}
output$plot <- renderggiraph({
ggiraph(code = print(gg_blahblah) )
})
```
## Selections
It is possible to work with selecteds point on a *ggiraph* plot within a Shiny application.
Selection can be of two types: `single` or `multiple`. The ggiraph's parameter `selection_type` will let you specify that.
```{r eval=FALSE}
output$myplot <- renderggiraph({
ggiraph(code = print(gg_blahblah), selection_type = "multiple" )
})
```
The selected points will be captured in the input reactive value `myplot_selected` (name of the input id of the reactive output value + `_selected`):
```{r eval=FALSE}
input$myplot_selected
```
You can also modify theses values by using the `session$sendCustomMessage` method with type `myplot_set` (name of the input id of the reactive output value + `_set`).
```{r eval=FALSE}
# delete selection
session$sendCustomMessage(type = 'myplot_set', message = character(0))
```
## Examples
The package contains Shiny examples available in the `shiny` directory of the package (`system.file("shiny", package = "ggiraph")`).
### selections usage (server side)
```{r eval=FALSE}
shiny::runApp(appDir = system.file("shiny/crimes", package = "ggiraph"), display.mode = "showcase")
shiny::runApp(appDir = system.file("shiny/cars", package = "ggiraph"), display.mode = "showcase")
# *group* selection
shiny::runApp(appDir = system.file("shiny/iris", package = "ggiraph"), display.mode = "showcase")
```
### onclick actions (client side).
```{r eval=FALSE}
shiny::runApp(appDir = system.file("shiny/DT", package = "ggiraph"), display.mode = "showcase")
```