如何从迷你图工具提示中的日期中删除逗号?

问题描述

我想从闪烁的工具提示中的日期中删除逗号,但我需要将它保留在值中。 我不完全理解 jQuery Sparkline 格式。

Sparkling tooltip example

library(shiny)
library(dplyr)

ui <- fluidPage(

  htmlwidgets::getDependency('sparkline'),DT::dataTableOutput("table")

)

server <- function(input,output) {

    raw_data <- data.frame(date = 2000:2021,value = sample(100:500,22))

  data <- raw_data %>%
    # Create the sparkline
    summarise("value" = sparkline::spk_chr(c(value),xvalues = date,tooltipformat = '{{x}}: {{y}}'))

  output$table <- DT::renderDataTable({

    cb <- htmlwidgets::JS('function(){debugger;HTMLWidgets.staticRender();}')

    DT::datatable(data = data,escape = FALSE,options = list(drawCallback = cb))
  })

}

shinyApp(ui,server)

解决方法

如定义的 here,您可以将 numberDigitGroupSep 设置为空字符串:

data <- raw_data %>%
    # Create the sparkline
    summarise(
        "value" = sparkline::spk_chr(
            c(value),numberDigitGroupSep = "",xvalues = date,tooltipFormat = '{{x}}: {{y}}'
        )
    )