carlganz / rintrojs

Wrapper for the Intro.js library
http://rintrojs.carlganz.com/
GNU Affero General Public License v3.0
133 stars 11 forks source link

enable mathjax, closes #39 #50

Closed etiennebacher closed 3 years ago

etiennebacher commented 3 years ago

This PR is greatly inspired by John Coene's commit in cicerone. Note that MathJax won't be applied if the delay in setTimeout is lower than 400.

Here's an example without any other code in onafterchange:

library(shiny)

ui <- shinyUI(fluidPage(
  introjsUI(),
  withMathJax(),
  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("$$y = x + 2$$", "$$y = x + 5$$")
  ))

  observeEvent(input$btn, {
    introjs(
      session,
      options = list(steps = steps()),
      events = list()
    )
  })

})

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

This also works when there is other code in onafterchange. Replace events = list() by the following:

events = list(
    onafterchange = I("console.log('hello')")
 )

and run it in browser to check the console.

carlganz commented 3 years ago

This is great! Thanks so much. A few changes:

Thanks again!

etiennebacher commented 3 years ago

I moved the code and added the condition. Concerning the NEWS.md, I added a new section but not sure if it's what you want.

Ah I just noticed that you already created a section for 0.3.0, but my branch wasn't up to date, I'll let you resolve the conflicts then (I don't think I can do something, right?) ;)