Awesome
<h3 align="center">shinyjs</h3> <h4 align="center"> ๐ก Easily improve the user experience of your Shiny apps in seconds <br><br> <a href="https://deanattali.com/shinyjs/">Official website</a> · by <a href="https://deanattali.com">Dean Attali</a> </h4> <p align="center"> <a href="https://github.com/daattali/shinyjs/actions"> <img src="https://github.com/daattali/shinyjs/workflows/R-CMD-check/badge.svg" alt="R build status" /> </a> <a href="https://cran.r-project.org/package=shinyjs"> <img src="https://www.r-pkg.org/badges/version/shinyjs" alt="CRAN version" /> </a> <a href="https://paypal.me/daattali/20"> <img src="http://i.imgur.com/vCIGFrH.png" /> </a> </p><img src="inst/img/hex.png" width="170" align="right"/>
{shinyjs} lets you perform common useful JavaScript operations in Shiny apps that will greatly improve your apps without having to know any JavaScript.
Examples include: hiding an element, disabling an input, resetting an input back to its original value, delaying code execution by a few seconds, and many more useful functions for both the end user and the developer. {shinyjs} can also be used to easily call your own custom JavaScript functions from R.
Need Shiny help? I'm available for consulting.<br/> If you find {shinyjs} useful, please consider supporting my work! โค
<p align="center"> <a style="display: inline-block;" href="https://github.com/sponsors/daattali"> <img height="35" src="https://i.imgur.com/034B8vq.png" /> </a> </p>This package is part of a larger ecosystem of packages with a shared vision: solving common Shiny issues and improving Shiny apps with minimal effort, minimal code changes, and clear documentation. Other packages for your Shiny apps:
Package | Description | Demo |
---|---|---|
shinyalert | ๐ฏ๏ธ Easily create pretty popup messages (modals) in Shiny | ๐ |
shinyscreenshot | ๐ท Capture screenshots of entire pages or parts of pages in Shiny apps | ๐ |
timevis | ๐ Create interactive timeline visualizations in R | ๐ |
shinycssloaders | โ Add loading animations to a Shiny output while it's recalculating | ๐ |
colourpicker | ๐จ A colour picker tool for Shiny and for selecting colours in plots | ๐ |
shinybrowser | ๐ Find out information about a user's web browser in Shiny apps | ๐ |
shinydisconnect | ๐ Show a nice message when a Shiny app disconnects or errors | ๐ |
shinytip | ๐ฌ Simple flexible tooltips for Shiny apps | WIP |
shinymixpanel | ๐ Track user interactions with Mixpanel in Shiny apps or R scripts | WIP |
shinyforms | ๐ Easily create questionnaire-type forms with Shiny | WIP |
Table of contents
- Demos and tutorials
- Sponsors ๐
- Overview of main functions
- Installation
- How to use
- Basic use case - complete working example
- Calling your own JavaScript functions from R
- FAQ and extra tricks
- Support
- Demo Shiny app that lets you play around with some of the functionality in {shinyjs}.
- Video of my {shinyjs} talk (30 min) and the corresponding presentation slides from the 2016 Shiny Developer Conference.
- Video of my {shinyjs} talk (5 min) and the corresponding presentation slides from the 2016 useR Conference.
There are no sponsors yet
Become the first sponsor for {shinyjs} and unlock special rewards!
<h2 id="overview-main"> Overview of main functions </h2>Note: In order to use any {shinyjs} function in a Shiny app, you must
first call useShinyjs()
anywhere in the appโs UI.
Functions that help you during Shiny app development
<table> <colgroup> <col style="width: 28%" /> <col style="width: 71%" /> </colgroup> <thead> <tr class="header"> <th>Function</th> <th>Description</th> </tr> </thead> <tbody> <tr class="odd"> <td><code>runcodeUI</code>+<code>runcodeServer</code></td> <td>Adds a text input to your app that lets you run arbitrary R code live.</td> </tr> <tr class="even"> <td><code>showLog</code></td> <td>Print any JavaScript <code>console.log()</code> messages in the R console, to make it easier and quicker to debug apps without having to open the JS console.</td> </tr> <tr class="odd"> <td><code>logjs</code></td> <td>Print a message to the JavaScript console (mainly used for debugging purposes).</td> </tr> <tr class="even"> <td><code>inlineCSS</code></td> <td>Easily add inline CSS to a Shiny app.</td> </tr> </tbody> </table>Check out the {shinyjs} demo app
to see some of these in action, or install {shinyjs} and run
shinyjs::runExample()
to see more demos.
For most users: To install the stable CRAN version:
install.packages("shinyjs")
For advanced users: To install the latest development version from GitHub:
install.packages("remotes")
remotes::install_github("daattali/shinyjs")
<h2 id="usage">
How to use
</h2>
A typical Shiny app has a UI portion and a server portion. Before using
most {shinyjs} functions, you need to call useShinyjs()
in the appโs
UI. Itโs best to include it near the top as a convention.
Here is a minimal Shiny app that uses {shinyjs}:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(), # Include shinyjs
actionButton("button", "Click me"),
textInput("text", "Text")
)
server <- function(input, output) {
observeEvent(input$button, {
toggle("text") # toggle is a shinyjs function
})
}
shinyApp(ui, server)
This is how most Shiny apps should initialize {shinyjs} - by calling
useShinyjs()
near the top of the UI.
However, if you use {shinyjs} in any of the following cases:
- In Shiny dashboards (built using the
shinydashboard
package) - In Shiny apps that use a
navbarPage
layout - In Rmd documents
- In Shiny apps that manually build the user interface with an HTML file or template (instead of using Shinyโs UI functions)
Then you should see the Including {shinyjs} in different types of apps document.
If your Shiny app doesnโt fall into any of these categories, then the above code sample should be enough to get your started with including {shinyjs} in your app.
<h2 id="usecase"> Basic use case - complete working example </h2>See the {shinyjs} example app walk-through document for a step-by-step guide on how to add a variety of {shinyjs} features to a simple app in order to make it more user friendly.
<h2 id="extendshinyjs"> Calling your own JavaScript functions from R </h2>You can also use {shinyjs} to add your own JavaScript functions that can
be called from R as if they were regular R functions using
extendShinyjs()
. This is only suitable for advanced users who are
familiar with JavaScript and wish to facilitate the communication
between R and JavaScript.
To learn about this feature and see how useful it can be, see the extendShinyjs: Calling your own JavaScript functions from R document.
<h2 id="faq-tricks"> FAQ and extra tricks </h2>There are several questions that pop up very frequently in my email or
on StackOverflow about โHow do I use {shinyjs} to do ___?โ Here is a
list of a few of these common questions with links to a solution that
could be useful. Note that all of these require using extendShinyjs()
.
- How do I show/hide the
shinydashboard
sidebar programmatically? - How do I hide/disable a tab?
- How do I refresh the page?
- How do I call a JavaScript function from a different JavaScript library?
- How do I change the values of a
sliderInput
? - How do I call JavaScript code and use the return value?
I also keep a long list of various Shiny tips & tricks for solving common Shiny problems, many of which make use of {shinyjs}.
<h2 id="support"> Support </h2>This document is only an overview of {shinyjs}. There are more in-depth resources available on the {shinyjs} website.
If you need help with {shinyjs}, free support is available on StackOverflow, RStudio Community, and Twitter.
Due to the large volume of requests I receive, Iโm unable to provide free support. If you canโt solve an issue and require paid help, please contact me.
<h2> Credits </h2>Logo design by Alfredo Hernรกndez.