首页 > 解决方案 > 如何将数据属性添加到 Shiny App 中的标签?

问题描述

在我的 Shiny App 中,我想为data一些标签添加属性。例如,

sliderInput("bins",
            "Number of bins:",
            min = 1,
            max = 50,
            value = 30,
            data-title = "Simple slider",
            data-intro = "This is a slider. Use it!")

 HTML("<h2 data-title = 'Welcome to LAI287 basal insulin study' 
      data-intro = 'This is a quick tour of the functionalities in this dashboard.'>
      LAI287 basal insulin study</h2>")

在这两种情况下,我都收到了很多错误。结果是添加data-titledata-intro让用户了解我的 Shiny App 中的功能。

标签: rshiny

解决方案


或许是这样的:

addAttributes <- function(slider){
  slider$children[[2]] <- htmltools::tagAppendAttributes(
    slider$children[[2]], 
    `data-title` = "Simple slider",
    `data-intro` = "This is a slider. Use it!"
  )
  slider
}

addAttributes(
  sliderInput("bins",
              "Number of bins:",
              min = 1,
              max = 50,
              value = 30
  )
)

推荐阅读