Skip to content

Commit c2d84a9

Browse files
committed
fix docs to account for new changes to handling complex cases
1 parent 9a943f1 commit c2d84a9

2 files changed

Lines changed: 5 additions & 32 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<img src="https://www.r-pkg.org/badges/version/shinyjs" alt="CRAN version" />
1616
</a>
1717
<a href="https://paypal.me/daattali/20">
18-
<img src="http://i.imgur.com/vCIGFrH.png" />
18+
<img src="https://i.imgur.com/vCIGFrH.png" />
1919
</a>
2020
</p>
2121

vignettes/shinyjs-usage.Rmd

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ knitr::opts_chunk$set(tidy = FALSE, comment = "#>")
2222
- [Using shinyjs with navbarPage layout](#usage-navbarpage)
2323
- [Using shinyjs in R Markdown documents](#usage-rmd)
2424
- [Rmd documents with Tabbed Sections](#usage-tabbed)
25-
- [Rmd documents using `shiny_prerendered` engine](#usage-prerendered)
2625
- [Using shinyjs when the user interface is built using an HTML file](#usage-html)
2726

2827
<h2 id="usage-basic">Basic use of shinyjs</h2>
@@ -120,12 +119,12 @@ shinyApp(ui, server)
120119

121120
<h2 id="usage-rmd">Using shinyjs in R Markdown documents</h2>
122121

123-
It is possible to embed Shiny components in an R Markdown document, resulting in interactive R Markdown documents. More information on how to use these documents is available [on the R Markdown website](https://bookdown.org/yihui/rmarkdown/shiny-documents.html). Even though interactive documents don't explicitly specify a UI and a server, using `shinyjs` is still easy: simply call `useShinyjs(rmd = TRUE)` (note the `rmd = TRUE` argument). For example, the following code can be used inside an R Markdown code chunk (assuming the Rmd document is set up with `runtime: shiny` as the link above describes):
122+
It is possible to embed Shiny components in an R Markdown document, resulting in interactive R Markdown documents. More information on how to use these documents is available [on the R Markdown website](https://bookdown.org/yihui/rmarkdown/shiny-documents.html). Even though interactive documents don't explicitly specify a UI and a server, all you need to do is call `useShinyjs()`. For example, the following code can be used inside an R Markdown code chunk (assuming the Rmd document is set up with `runtime: shiny` as the link above describes):
124123

125124
```
126125
library(shinyjs)
127126
128-
useShinyjs(rmd = TRUE)
127+
useShinyjs()
129128
actionButton("button", "Click me")
130129
div(id = "hello", "Hello!")
131130
@@ -136,36 +135,10 @@ observeEvent(input$button, {
136135

137136
<h3 id="usage-tabbed">Rmd documents with Tabbed Sections</h3>
138137

139-
If the Rmd file makes use of [Tabbed Sections](https://bookdown.org/yihui/rmarkdown/html-document.html#tabbed_sections) (using `{.tabset}`), then you should include the call to `useShinyjs(rmd = TRUE)` before the tabset definition, near the beginning of the file.
140-
141-
<h3 id="usage-prerendered">Rmd documents using `shiny_prerendered` engine</h3>
142-
143-
If you're using the [`shiny_prerendered` Rmd format](https://bookdown.org/yihui/rmarkdown/shiny-documents.html), you need to include the following code in the beginning of your Rmd file, just after the YAML header (you need to remove the spaces between the backticks to make this code work):
144-
145-
````
146-
`r ''````{r, echo=FALSE}
147-
shiny::addResourcePath("shinyjs", system.file("srcjs", package = "shinyjs"))
148-
```
149-
`r ''````{r, context="server"}
150-
shinyjs::useShinyjs(html = TRUE)
151-
```
152-
<script src="shinyjs/inject.js"></script>
153-
````
138+
If the Rmd file makes use of [Tabbed Sections](https://bookdown.org/yihui/rmarkdown/html-document.html#tabbed-sections) (using `{.tabset}`), then you should include the call to `useShinyjs()` before the tabset definition, near the beginning of the file.
154139

155140
<h2 id="usage-html">Using shinyjs when the user interface is built using an HTML file/template</h2>
156141

157142
While most Shiny apps use Shiny's functions to build a user interface to the app, it is possible to build the UI with an HTML template, [as RStudio shows in this article](https://shiny.rstudio.com/articles/templates.html). In this case, you simply need to add `{{ useShinyjs() }}` somewhere in the template, preferably inside the `<head>...</head>` tags.
158143

159-
A similar way to create your app's UI with HTML is to write it entirely in HTML (without templates), [as RStudio shows in this article](https://shiny.rstudio.com/articles/html-ui.html). Building Shiny apps like this is much more complicated and should only be used if you're very comfortable with HTML. Using `shinyjs` in these apps is possible but it works a little differently since there is no `ui.R` to call `useShinyjs()` from. There are three simple steps to take in order to use `shinyjs` in these apps:
160-
161-
- Create a `global.R` file in the same directory as your `server.R`, and add the following line to the file:
162-
163-
shiny::addResourcePath("shinyjs", system.file("srcjs", package = "shinyjs"))
164-
165-
- In the `index.html` file you need to load a special JavaScript file named `shinyjs/inject.js`. You do this by adding the following line to the HTML's `<head>` tag:
166-
167-
`<script src="shinyjs/inject.js"></script>`
168-
169-
- In your server function (the `shinyServer` function) you need to call `useShinyjs(html = TRUE)`
170-
171-
After adding these three lines to your code, you can use all `shinyjs` functions as usual.
144+
A similar way to create your app's UI with HTML is to write it entirely in HTML (without templates), [as RStudio shows in this article](https://shiny.rstudio.com/articles/html-ui.html). Building Shiny apps like this is much more complicated and should only be used if you're very comfortable with HTML. Using `shinyjs` in these apps is possible but it works a little differently since there is no `ui.R` to call `useShinyjs()` from. In this case, you need to call `insertUI("head", "beforeEnd", immediate = TRUE, ui = useShinyjs())` in the server. If you wish to use `extendShinyjs()`, then a similar line needs to be added in the server.

0 commit comments

Comments
 (0)