MyNixOS website logo
Description

Wrapper for the 'Intro.js' Library.

A wrapper for the 'Intro.js' library (For more info: <https://introjs.com/>). This package makes it easy to include step-by-step introductions, and clickable hints in a 'Shiny' application. It supports both static introductions in the UI, and programmatic introductions from the server-side.

JOSSStatus ProjectStatus:Active. R-CMD-check CRAN_Status_Badge Licence minimalRversion

rintrojs

R was originally developed with the name S in the 70’s as a glue language. Statisticians at Bell Labs needed an interactive environment for working with their C and Fortran scripts. Decades later, R is still a glue language, except instead of C and Fortran, it brings together C++, and JavaScript. With the advent of the Shiny package, R is now a popular platform for developing data-driven web applications. As Shiny increases in popularity so will the complexity of the Shiny apps built. In many instances, new-users will require guidance when they first use a Shiny application.

Luckily, there is already a well established JavaScript library for this purpose. Intro.js, written by Afshin Mehrabani, is a JavaScript library that helps integrate step-by-step introductions, and clickable hints into websites. The rintrojs R package integrates Intro.js into Shiny, so that users can easily add instructions to their application without having to use HTML, CSS, or JavaScript.

Install

rintrojs is available on CRAN:

install.packages("rintrojs")

To access the bleeding-edge version, use devtools to install rintrojs from github:

devtools::install_github("carlganz/rintrojs")

Usage

To use rintrojs, you need to call introjsUI() once in the UI. rintrojs supports both static and programmatic introductions meaning you can either wrap the elements you want to introduce with introBox, or dynamically generate your introduction using the steps option (see the Intro.js documentaion). You specify the order of the introduction with the data.step parameter, and you specify the content of the introduction with the data.intro parameter. You can initiate the introduction from the server by calling introjs(session). You can also specify options, and pass text as the body of javascript events associated with Intro.js.

Here is an example with a static introduction, but with options, and events used.

library(rintrojs)
library(shiny)

# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(
  introjsUI(),
  
  # Application title
  introBox(
    titlePanel("Old Faithful Geyser Data"),
    data.step = 1,
    data.intro = "This is the title panel"
  ),
  
  # Sidebar with a slider input for number of bins
  sidebarLayout(sidebarPanel(
    introBox(
      introBox(
        sliderInput(
          "bins",
          "Number of bins:",
          min = 1,
          max = 50,
          value = 30
        ),
        data.step = 3,
        data.intro = "This is a slider",
        data.hint = "You can slide me"
      ),
      introBox(
        actionButton("help", "Press for instructions"),
        data.step = 4,
        data.intro = "This is a button",
        data.hint = "You can press me"
      ),
      data.step = 2,
      data.intro = "This is the sidebar. Look how intro elements can nest"
    )
  ),
  
  # Show a plot of the generated distribution
  mainPanel(
    introBox(
      plotOutput("distPlot"),
      data.step = 5,
      data.intro = "This is the main plot"
    )
  ))
))

# Define server logic required to draw a histogram
server <- shinyServer(function(input, output, session) {
  # initiate hints on startup with custom button and event
  hintjs(session, options = list("hintButtonLabel"="Hope this hint was helpful"),
         events = list("onhintclose"=I('alert("Wasn\'t that hint helpful")')))
  
  output$distPlot <- renderPlot({
    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    # draw the histogram with the specified number of bins
    hist(x,
         breaks = bins,
         col = 'darkgray',
         border = 'white')
  })
  
  # start introjs when button is pressed with custom options and events
  observeEvent(input$help,
               introjs(session, options = list("nextLabel"="Onwards and Upwards",
                                               "prevLabel"="Did you forget something?",
                                               "skipLabel"="Don't be a quitter"),
                                events = list("oncomplete"=I('alert("Glad that is over")')))
  )
})

# Run the application
shinyApp(ui = ui, server = server)

You can also generate introductions dynamically.

library(shiny)
library(rintrojs)

ui <- shinyUI(fluidPage(
      introjsUI(),
      mainPanel(
        textInput("intro","Enter an introduction"),
         actionButton("btn","Press me")
      )
   )
)

server <- shinyServer(function(input, output, session) {
   
  steps <- reactive(data.frame(element = c(NA,"#btn"),
                               intro = c(input$intro,"This is a button")))
  
  observeEvent(input$btn,{
    introjs(session,options = list(steps=steps()))
    
  })
  
})

# Run the application 
shinyApp(ui = ui, server = server)

Click here to view example.

Contributing

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

If you find any problems or have any questions, please feel free to file an issue.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Carl Ganz
Afshin Mehrabani
Etienne Bacher
Matthew van Bommel
Chris Baker

This project follows the all-contributors specification. Contributions of any kind welcome!

Metadata

Version

0.3.4

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows