![]() Now I can simply call hide("panel") or disable("button"). Simple things like showing/hiding elements, enabling/disabling a button, showing a popup message to the user, manipulating the CSS class or HTML content of an element, etc.Īfter noticing that I'm writing the same JS code in all my apps, and since making Shiny talk to JS is a bit tedious and annoying with all the message passing, I decided to just package it to make it easily reusable. But there are just a few simple pieces of functionality that I always find missing and I implement myself in my Shiny apps using JavaScript (JS) because it's either not supported natively by Shiny or it's just cleaner to do so. It's very powerful and one of the most useful packages in my opinion. Shiny is a fantastic R package provided by RStudio that lets you turn any R code into an interactive webpage. More information is available in the section "Calling your own JavaScript functions from R".Ĭheck out the demo Shiny app to see some of these in action, or install shinyjs and run shinyjs::runExample() to see more demo apps. Runjs - run arbitrary JavaScript code (not recommended to use this in a published Shiny app).ĮxtendShinyjs - allows you to write your own JavaScript functions and use shinyjs to call them as if they were regular R code. Logjs - print a message to the JavaScript console (mainly used for debugging purposes). InlineCSS - easily add inline CSS to a Shiny app. Was originally developed with the sole purpose of running a shinyjs function when an element is clicked, though any R code can be used.ĪddClass/ removeClass/ toggleClass - add or remove a CSS class from an element ![]() Onclick - run R code when an element is clicked. Text - change the text/HTML of an element (using JavaScript's innerHTML under the hood). Info - show a message to the user (using JavaScript's alert under the hood). Reset - reset a Shiny input widget back to its original value.Įnable/ disable/ toggleState - enable or disable an input element, such as a button or a text input. Hidden - initialize a Shiny tag as invisible (can be shown later with a call to show). There are arguments that control the animation as well, though animation is off by default. ![]() Show/ hide/ toggle - display or hide an element. To install the latest developmental version from GitHub: install.packages("devtools")ĭevtools::install_github("daattali/shinyjs") Overview of main functions ![]() To install the CRAN version: install.packages("shinyjs") Shinyjs is available through both CRAN and GitHub: You can check out a demo Shiny app that lets you play around with some of the functionality that shinyjs makes available, or have a look at a very basic Shiny app that uses shinyjs to enhance the user experience with very minimal and simple R code. shinyjs can also be used to easily run your own custom JavaScript functions from R. Examples include hiding an element, disabling an input, resetting an input back to its original value, and many more useful functions. Shinyjs lets you perform common useful JavaScript operations in Shiny applications without having to know any JavaScript. Shinyjs - Perform common JavaScript operations in Shiny apps using plain R code ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |