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
-[Using shinyjs with navbarPage layout](#usage-navbarpage)
23
23
-[Using shinyjs in R Markdown documents](#usage-rmd)
24
24
-[Rmd documents with Tabbed Sections](#usage-tabbed)
25
-
-[Rmd documents using `shiny_prerendered` engine](#usage-prerendered)
26
25
-[Using shinyjs when the user interface is built using an HTML file](#usage-html)
27
26
28
27
<h2id="usage-basic">Basic use of shinyjs</h2>
@@ -120,12 +119,12 @@ shinyApp(ui, server)
120
119
121
120
<h2id="usage-rmd">Using shinyjs in R Markdown documents</h2>
122
121
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):
<h3id="usage-tabbed">Rmd documents with Tabbed Sections</h3>
138
137
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
-
<h3id="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):
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.
154
139
155
140
<h2id="usage-html">Using shinyjs when the user interface is built using an HTML file/template</h2>
156
141
157
142
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.
158
143
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:
- 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