shinyalert

πŸ—―οΈ Easily create pretty popup messages (modals) in Shiny

https://github.com/daattali/shinyalert

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • β—‹
    CITATION.cff file
  • βœ“
    codemeta.json file
    Found codemeta.json file
  • β—‹
    .zenodo.json file
  • β—‹
    DOI references
  • β—‹
    Academic publication links
  • β—‹
    Committers with academic emails
  • β—‹
    Institutional organization owner
  • β—‹
    JOSS paper metadata
  • β—‹
    Scientific vocabulary similarity
    Low similarity (12.1%) to scientific vocabulary

Keywords

r r-package rstats shiny shiny-r

Keywords from Contributors

report
Last synced: 9 months ago · JSON representation

Repository

πŸ—―οΈ Easily create pretty popup messages (modals) in Shiny

Basic Info
Statistics
  • Stars: 243
  • Watchers: 4
  • Forks: 27
  • Open Issues: 5
  • Releases: 5
Topics
r r-package rstats shiny shiny-r
Created over 9 years ago · Last pushed about 2 years ago
Metadata Files
Readme Funding License

README.md

shinyalert

πŸ—―οΈ Easily create pretty popup messages (modals) in Shiny

Demo · by Dean Attali

R build status CRAN version


{shinyalert} lets you easily create pretty popup messages (modals) in Shiny.

Modals can contain text, images, OK/Cancel buttons, Shiny inputs, and Shiny outputs (such as plots and tables). A modal can also have a timer to close automatically, and you can specify custom code to run when a modal closes. See the demo Shiny app online for examples.

Need Shiny help? I'm available for consulting.
If you find {shinyalert} useful, please consider supporting my work! ❀

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 | |---|---|---| | shinyjs | πŸ’‘ Easily improve the user experience of your Shiny apps in seconds | πŸ”— | | 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

Examples

Example 1: Simple modal

basic modal

Example 2: Simple input modals

input modal

Example 3: Shiny inputs/outputs in modals

Shiny inputs

Example 4: Chaining modals

chaining modals

Sponsors πŸ†

There are no sponsors yet

Become the first sponsor for {shinyalert}!

Overview

{shinyalert} uses the sweetalert JavaScript library to create simple and elegant popups (modals) in Shiny.

Simply call shinyalert() with the desired arguments, such as a title and text, and a modal will show up. Here is a minimal Shiny app code that creates a modal:

``` library(shiny) library(shinyalert)

ui <- fluidPage( actionButton("preview", "Preview") )

server <- function(input, output, session) { observeEvent(input$preview, { # Show a modal when the button is pressed shinyalert("Oops!", "Something went wrong.", type = "error") }) }

shinyApp(ui, server) ```

Installation

For most users: To install the stable CRAN version:

r install.packages("shinyalert")

For advanced users: To install the latest development version from GitHub:

r install.packages("remotes") remotes::install_github("daattali/shinyalert")

Simple input modals

Usually the purpose of a modal is simply informative, to show some information to the user. However, the modal can also be used to retrieve an input from the user by setting the type = "input" parameter.

When using a type="input" modal, only a single input can be used. By default, the input will be a text input, but you can use other input types by specifying the inputType parameter (for example inputType = "number" will expose a numeric input).

Shiny inputs/outputs in modals

While simple input modals are useful for retrieving input from the user, they aren't very flexible - they only allow one input. You can include any Shiny UI code in a modal, including Shiny inputs and outputs (such as plots), by providing Shiny tags in the text parameter and setting html=TRUE. For example, the following code would produce a modal with two inputs:

shinyalert(html = TRUE, text = tagList( textInput("name", "What's your name?", "Dean"), numericInput("age", "How old are you?", 30) ))

Modal return value

Modals created with {shinyalert} have a return value when they exit.

When using a simple input modal (type="input"), the value of the modal is the value the user entered. Otherwise, the value of the modal is TRUE if the user clicked the "OK" button, and FALSE if the user dismissed the modal (either by clicking the "Cancel" button, using the Escape key, clicking outside the modal, or letting the timer run out).

The return value of the modal can be accessed via input$shinyalert (or using a different input ID if you specify the inputId parameter), as if it were a regular Shiny input. The return value can also be accessed using the modal callbacks.

Callbacks

The return value of the modal is passed as an argument to the callbackR and callbackJS functions (if a callbackR or callbackJS arguments are provided). These functions get called (in R and in JavaScript, respectively) when the modal exits.

For example, using the following {shinyalert} code will result in a modal with an input field. After the user clicks "OK", a hello message will be printed to both the R console and in a native JavaScript alert box. You don't need to provide both callback functions, but in this example both are used for demonstration.

shinyalert( "Enter your name", type = "input", callbackR = function(x) { message("Hello ", x) }, callbackJS = "function(x) { alert('Hello ' + x); }" )

Notice that the callbackR function accepts R code, while the callbackJS function uses JavaScript code.

Since closing the modal with the Escape key results in a return value of FALSE, the callback functions can be modified to not print anything in that case.

shinyalert( "Enter your name", type = "input", callbackR = function(x) { if(x != FALSE) message("Hello ", x) }, callbackJS = "function(x) { if (x !== false) { alert('Hello ' + x); } }" )

Chaining modals

It's possible to chain modals (call multiple modals one after another) by making a shinyalert() call inside a {shinyalert} callback or using the return value of a previous modal. For example:

shinyalert( title = "What is your name?", type = "input", callbackR = function(value) { shinyalert(paste("Welcome", value)) } )

Using in Rmarkdown files

You can use {shinyalert} in Rmarkdown documents as well. This only works in interactive Rmd documents (when runtime: shiny is used in the YAML).

````

output: html_document

runtime: shiny

```{r} library(shinyalert)

textInput("name", "Name") actionButton("button", "Click me")

observeEvent(input$button, { shinyalert(title = "Hey", text = input$name) }) `

Pre-loading the scripts

The first time a {shinyalert} message is shown, the required scripts are automatically inserted to the Shiny app. In real browsers (Chrome/Firefox/etc) this is not an issue, but in some contexts, such as inside RStudio's Viewer on some operating systems, this can sometimes cause the modal to appear glitchy for a brief moment until the scripts load.

If you notice this behaviour and prefer to pre-load the scripts when the Shiny app initializes, you can call useShinyalert(force=TRUE) anywhere in the UI. Note that calling useShinyalert() is NOT required.

Comparison with Shiny modals

Doesn't Shiny already have support for modals?

Yes, it does.

And Shiny's modals are just fine.

I created {shinyalert} for two reasons: first of all, I started working on it well before Shiny had modals. But I decided to keep working on it and release it even afterwards because I find {shinyalert} to be easier to use and to result in much nicer modals. There are also some extra features in {shinyalert}, such as the callback functions and the timer. But ultimately it's a matter of convenience and aesthetics.

Known issues

  • Clicking any <button> tag inside a modal will close the modal. This is due to the underlying JavaScript library having this issue. This means that, for example, using radio buttons from {shinyWidgets} will cause this bug because their radio buttons are implemented using <button>.
  • Chaining modals works fine when the modals contain only text, but when inputs or buttons are involved in chained modals, you may run into an issue such as this one or this one.

Credits

Logo design by Alfredo HernΓ‘ndez.

Owner

  • Name: Dean Attali
  • Login: daattali
  • Kind: user
  • Location: Toronto
  • Company: AttaliTech Ltd

Founder & Lead R-Shiny consultant @ AttaliTech Ltd. Passionate about writing open source tools. Extreme traveller.

GitHub Events

Total
  • Watch event: 2
  • Fork event: 2
Last Year
  • Watch event: 2
  • Fork event: 2

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 105
  • Total Committers: 3
  • Avg Commits per committer: 35.0
  • Development Distribution Score (DDS): 0.019
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Dean Attali d****i@g****m 103
ch0c0l8ra1n r****5@g****m 1
Etienne Bacher 5****r 1

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 79
  • Total pull requests: 10
  • Average time to close issues: about 2 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 51
  • Total pull request authors: 7
  • Average comments per issue: 2.85
  • Average comments per pull request: 4.5
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 2
  • Pull request authors: 0
  • Average comments per issue: 2.67
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • daattali (25)
  • stla (3)
  • JamesBrownSEAMS (2)
  • gueyenono (2)
  • BonnyRead (1)
  • mauromiguelm (1)
  • alipprc (1)
  • lbusett (1)
  • gwiesner (1)
  • nick-youngblut (1)
  • dleopold (1)
  • dkulp2 (1)
  • gdlr (1)
  • karolinakamuda (1)
  • charleswidnall (1)
Pull Request Authors
  • ch0c0l8ra1n (4)
  • dipterix (2)
  • daattali (2)
  • drzamich (1)
  • galachad (1)
  • lgaborini (1)
  • etiennebacher (1)
Top Labels
Issue Labels
help wanted (4) bug (3)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 10,136 last-month
  • Total docker downloads: 311,862
  • Total dependent packages: 30
    (may contain duplicates)
  • Total dependent repositories: 121
    (may contain duplicates)
  • Total versions: 8
  • Total maintainers: 1
cran.r-project.org: shinyalert

Easily Create Pretty Popup Messages (Modals) in 'Shiny'

  • Versions: 5
  • Dependent Packages: 30
  • Dependent Repositories: 120
  • Downloads: 10,136 Last month
  • Docker Downloads: 311,862
Rankings
Stargazers count: 1.9%
Dependent repos count: 2.0%
Dependent packages count: 2.6%
Forks count: 3.2%
Downloads: 3.8%
Average: 3.8%
Docker downloads count: 9.2%
Maintainers (1)
Last synced: over 1 year ago
conda-forge.org: r-shinyalert
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Dependent repos count: 24.4%
Stargazers count: 25.7%
Forks count: 33.7%
Average: 33.9%
Dependent packages count: 51.6%
Last synced: 10 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.0.2 depends
  • htmltools * imports
  • knitr * imports
  • shiny >= 1.0.4 imports
  • stats * imports
  • uuid * imports
  • colourpicker * suggests
  • shinydisconnect * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • actions/upload-artifact main composite
  • r-lib/actions/setup-pandoc v1 composite
  • r-lib/actions/setup-r v1 composite