Skip to content

Commit

Permalink
add documentation for how to use shinyjs with the new html templates …
Browse files Browse the repository at this point in the history
…feature; fixes #55
  • Loading branch information
daattali committed Apr 24, 2016
1 parent d7f0cfe commit f5635d4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinyjs
Title: Perform Common JavaScript Operations in Shiny Apps using Plain R Code
Version: 0.5.4
Version: 0.6
Authors@R: person("Dean", "Attali", email = "[email protected]",
role = c("aut", "cre"))
Description: Perform common JavaScript operations in Shiny applications without
Expand Down
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# shinyjs 0.5.4
# shinyjs 0.6

2016-04-21
2016-04-24

- `info()` fuction: don't include surrounding quotations if not necessary (#59)
- added documentation for how to use `shinyjs` in HTML templates

# shinyjs 0.5.3

Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
NOTE: During March/April 2016 I will be extremely busy trying to write my thesis, so please do not send me private emails asking for personal help. If you need help, I recommend you ask on StackOverflow. Help me graduate :)
==================================================================================================================================================================================================================================

shinyjs - Perform common JavaScript operations in Shiny apps using plain R code
===============================================================================

Expand Down Expand Up @@ -162,15 +159,14 @@ that uses `shinyjs`:

shinyApp(ui, server)

This is how most Shiny apps should initialize `shinyjs`, but there are
four common scenarios that should be treated a little differently: using
`shinyjs` in Shiny dashboards, in Shiny apps that use a `navbarPage`
layout, in interactive documents, or in Shiny apps that manually build
the user interface with an HTML file instead of using Shiny's UI
functions. If your Shiny app doesn't fall into any of these categories
(most Shiny apps don't), then you can skip the next 4 sections that
describe how to tackle these cases, and scroll down to the [Basic use
case](#usecase) section.
This is how most Shiny apps should initialize `shinyjs`, but there a few
scenarios that should be treated a little differently: using `shinyjs`
in Shiny dashboards, in Shiny apps that use a `navbarPage` layout, in
interactive Rmd documents, or in Shiny apps that manually build the user
interface with an HTML file or template instead of using Shiny's UI
functions. If your Shiny app doesn't fall into any of these categories,
then you can skip the next 4 sub-sections that describe how to tackle
these cases, and scroll down to the [Basic use case](#usecase) section.

<h3 id="usage-dashboard">
Using shinyjs in Shiny Dashboards
Expand Down Expand Up @@ -263,11 +259,18 @@ Shiny document as the link above describes):
})

<h3 id="usage-html">
Using shinyjs when the user interface is built using an HTML file
Using shinyjs when the user interface is built using an HTML
file/template
</h3>
While most Shiny apps use Shiny's functions to build a user interface to
the app, it is possible to build the entire UI with custom HTML, [as
the app, it is possible to build the UI with an HTML template, [as
RStudio shows in this
article](http://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.

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](http://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
Expand All @@ -290,7 +293,7 @@ to use `shinyjs` in these apps:
call `useShinyjs(html = TRUE)`

After adding these three lines to your code, you can use all `shinyjs`
functions as normal.
functions as usual.

<h2 id="usecase">
Basic use case - complete working example
Expand Down
2 changes: 1 addition & 1 deletion inst/srcjs/shinyjs-default-funcs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// shinyjs 0.5.4 by Dean Attali
// shinyjs 0.6 by Dean Attali
// Perform common JavaScript operations in Shiny apps using plain R code

shinyjs = function() {
Expand Down
12 changes: 6 additions & 6 deletions vignettes/overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ vignette: >
knitr::opts_chunk$set(tidy = FALSE, comment = "#>")
```

# NOTE: During February/March 2016 I will be extremely busy trying to write my thesis, so please do not send me private emails asking for personal help. If you need help, I recommend you ask on StackOverflow. Help me graduate :)

# shinyjs - Perform common JavaScript operations in Shiny apps using plain R code

[![Build Status](https://travis-ci.org/daattali/shinyjs.svg?branch=master)](https://travis-ci.org/daattali/shinyjs)
Expand Down Expand Up @@ -156,7 +154,7 @@ server <- function(input, output) {
shinyApp(ui, server)
```

This is how most Shiny apps should initialize `shinyjs`, but there are four common scenarios that should be treated a little differently: using `shinyjs` in Shiny dashboards, in Shiny apps that use a `navbarPage` layout, in interactive documents, or in Shiny apps that manually build the user interface with an HTML file instead of using Shiny's UI functions. If your Shiny app doesn't fall into any of these categories (most Shiny apps don't), then you can skip the next 4 sections that describe how to tackle these cases, and scroll down to the [Basic use case](#usecase) section.
This is how most Shiny apps should initialize `shinyjs`, but there a few scenarios that should be treated a little differently: using `shinyjs` in Shiny dashboards, in Shiny apps that use a `navbarPage` layout, in interactive Rmd documents, or in Shiny apps that manually build the user interface with an HTML file or template instead of using Shiny's UI functions. If your Shiny app doesn't fall into any of these categories, then you can skip the next 4 sub-sections that describe how to tackle these cases, and scroll down to the [Basic use case](#usecase) section.

<h3 id="usage-dashboard">Using shinyjs in Shiny Dashboards</h3>

Expand Down Expand Up @@ -230,9 +228,11 @@ observeEvent(input$button, {
})
```

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

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](http://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.

While most Shiny apps use Shiny's functions to build a user interface to the app, it is possible to build the entire UI with custom HTML, [as RStudio shows in this article](http://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:
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](http://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:

- create a `global.R` file in the same directory as your `server.R`, and add the following line to the file:

Expand All @@ -244,7 +244,7 @@ While most Shiny apps use Shiny's functions to build a user interface to the app
- in your server function (the `shinyServer` function) you need to call `useShinyjs(html = TRUE)`

After adding these three lines to your code, you can use all `shinyjs` functions as normal.
After adding these three lines to your code, you can use all `shinyjs` functions as usual.


<h2 id="usecase">Basic use case - complete working example</h2>
Expand Down

0 comments on commit f5635d4

Please sign in to comment.