r - 添加 UI 元素的一部分作为 introjs() 教程的步骤

标签 r shiny intro.js

使用 introjs() 时是否可以将 UI 的一部分(例如 renderDataTable 的过滤器部分)添加到介绍步骤?

示例: 我希望用户知道他们可以使用表的过滤器部分来过滤结果。因此,作为附加步骤,我想突出显示数据表的过滤器部分,作为本教程的步骤之一。

library(shiny)
library(DT)
library(rintrojs)

ui <- fluidPage(
    introjsUI(),  # include introjs
    div(id = "intro", h3("Intro")),
    dataTableOutput("my_table")
)


server <- function(input, output, session) {
    output$my_table <- renderDataTable({
        datatable(iris, filter = 'top')
    })
    
    # Trigger introjs on app start
        introjs(session, options = list(steps = list(
            list(element = "#intro", intro = "Intro"),
            list(element = "#my_table", intro = "This is the table. Now zooming in on filters...")
        )))
}

shinyApp(ui, server)

最佳答案

您可以添加任何有效的 CSS 选择器,因此您所需要做的就是找到一种正确的方法来寻址包含过滤器元素的行。此外,由于数据表是动态呈现的,因此您不应该太早调用 introjs,否则您尝试定位的元素尚不存在。一个不错的选择是在系统第一次刷新时调用 introjs,其中数据表已填充。

将所有内容放在一起,以下代码片段实现了该功能:

# Trigger introjs on app start but not before the system is flushed
session$onFlushed(function() {
  introjs(session, options = list(steps = list(
    list(element = "#intro", intro = "Intro"),
    list(element = "#my_table", intro = "This is the table. Now zooming in on filters..."),
    ### :nth-of-type will select the second row (<tr>), that is where the filters are
    list(element = "tr:nth-of-type(2)", intro = "Here you can apply filters")
  )))
})

关于r - 添加 UI 元素的一部分作为 introjs() 教程的步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77669034/

相关文章:

r - R Shiny 中带有 leafletProxy 的 Leaflet drawToolbar

使用 AWS Cognito 进行 R Shiny 身份验证

r - 在 `geom_hline` 图中设置 `geom_bar` 的长度

r - 如何用按平均值着色的较小矩形填充矩形

r - 如何在R中的相关矩阵中提取相邻变量之间的值?

javascript - 向数据表中的项目添加 "data"选项

javascript - 如何在单个网页中使用 introJs 设置两个介绍之旅?

R XML : How to retrieve a node with a given value

r - 根据之前在 R Shiny 中的选择显示下拉选择

javascript - Css 不适用于 React 中的 intro.js 模块