Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

'on_highlighted' argument is triggered at the start of the tour #15

Description

@thiagomaf

I am running a Cicerone tour as a tutorial of my shinydashboard app UI. The idea is to walk the user thru the various inputs in the interface. Some of these inputs are present inside boxes which are presumably collapsed at the start of the tour, my goal is to use the 'on_highlighted' argument to trigger a shinysj toggle command at a given specific step().

The toggle command works fine independently. The Cicerone tour works fine independently. But the shinyjs is not trigerred at the specific step() but rather at the start of the tour (i.e. before first step()).

Below an example:

library(shiny)
library(shinydashboard)
library(cicerone)
library(shinyjs)

jscode <- "
shinyjs.collapse = function(boxid) {
$('#' + boxid).closest('.box').find('[data-widget=collapse]').click();
}
"

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    useShinyjs(),
    extendShinyjs(text = jscode, functions = "collapse"),

    use_cicerone(),
    
    div(
      box(
        textInput(
          inputId     = "text1",
          label       = "Text 1",
          value       = "",
          placeholder = "Text 1"
        ),
        
        textInput(
          inputId     = "text2",
          label       = "Text 2",
          value       = "",
          placeholder = "Text 2"
        ),
        
        textInput(
          inputId     = "text3",
          label       = "Text 3",
          value       = "",
          placeholder = "Text 3"
        ),
      )
    ),
    
    box(
      id          = "super_box",
      title       = "Expandable box",
      solidHeader = TRUE,
      collapsible = TRUE,
      collapsed   = TRUE,
      
      "Stuff inside the box!",
      textInput(
        inputId     = "text4",
        label       = "Text 4",
        value       = "",
        placeholder = "Text 4"
      )
    ),
    
    actionButton(inputId = "tutorial", label = "Tutorial"),
    actionButton(inputId = "expand",   label = "Expand")
  )
)

server <- function(input, output) {
  observeEvent(input$expand, {
    js$collapse("super_box")
  })
  
  observeEvent(input$tutorial, {
    Cicerone$
      new()$
      step(
        el          = "text1",
        title       = "Text 1",
        class       = "popover",
        description = "Info 1"
      )$
      step(
        el          = "text2",
        title       = "Text 2",
        class       = "popover",
        description = "Info 2"
      )$
      step(
        el          = "text3",
        title       = "Text 3",
        class       = "popover",
        description = "Info 3"
      )$
      step(
        el          = "text4",
        title       = "Expand box",
        class       = "popover",
        description = "Is it expanded?",
        on_highlighted = js$collapse("super_box")
      )$
      init()$
      start()
  })
}

shinyApp(ui, server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions