forked from ThinkR-open/engineering-shiny-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.Rmd
65 lines (36 loc) · 1.6 KB
/
javascript.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
# Using JavaSript {#optimjs}
## Client-side Optimization
// TODO
## JavaScript <-> Shiny communication
// TODO
## Common JavaScript patterns for Shiny
// TODO
## About `{golem}` js functions
`{golem}` comes with a series of JavaScript functions that you can call from the server.
These functions are added by default with `golem::activate_js()` in `app_ui`.
Then they are called with `golem::invoke_js("function", "ui_element")`.
This `ui_element` define the UI element to interact with.
It can be a full jQuery selector, an id or a class.
### `golem::activate_js()`
+ `showid` & `hideid`, `showclass` & `hideclass` show and hide elements through their id or class.
```{r eval = FALSE}
session$sendCustomMessage("showid", ns("plot"))
```
+ `showhref` & `hidehref` hide and show a link by trying to match the `href` content.
```{r eval = FALSE}
session$sendCustomMessage("showhref", "panel2")
```
+ `clickon` click on the element. You have to use the full jQuery selector.
+ `show` & `hide` show and hide elements, using the full jQuery selector.
### About jQuery selectors
+ `#plop`: the element with the id `plop`
+ `.pouet`: elements of class `pouet`
+ `"button:contains('this')"`: buttons with a text containing `'this'`
Note that in html, tags contains attributes. For example:
``` html
<a href = "https://thinkr.fr" data-value = "panel2">ThinkR</a>
```
contains `href` & `data-value`.
You can refer to these attributes with `[]` after the tag name.
+ `a[href = "https://thinkr.fr"]`: link with `href` being `https://thinkr.fr`
+ `a[data-value="panel2"]`: link with `data-value` being `"panel2"`