gpt4 book ai didi

javascript - 需要替换 Shiny R renderDataTable 中的默认 "No data available in table"消息

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:30:35 24 4
gpt4 key购买 nike

我不太了解 JavaScript,当我输出表格时,我无法覆盖 Shiny R App 中的默认消息。

当表为空时,它会在第一行给出消息 “表中没有可用数据”。我想改为放置一些特定于应用程序的说明。

我发现有这样的东西:options = list(searching = FALSE,paging = FALSE) 但不知道切换该文本的选项是什么。

此外,我还找到了重置消息的 JS 代码 ( https://datatables.net/reference/option/language.zeroRecords ),但我无法将其正确附加到 Shiny 中的 renderDataTable。我只是不知道将 JS 合并到 shiny 中的正确语法,我试过了

options = list(searching = FALSE,paging = FALSE, callback=DT:JS(
'
{
"language": {
"zeroRecords": "No records to display- custom text"
}
'

但是没有用。我将不胜感激对此的一些指导。这是整个代码。现在我尝试替换消息的尝试被忽略了:

library(ggplot2)
library(DT)
ui <- fluidPage(
titlePanel("Basic DataTable"),

# Create a new Row in the UI for selectInputs
fluidRow(
column(12,
selectInput("man",
"Manufacturer:",
c("All",
unique(as.character(mpg$manufacturer))))
)
),
# Create a new row for the table.
fluidRow(
DT::dataTableOutput("table")
)
)
server <-function(input, output) {

# Filter data based on selections
output$table <- DT::renderDataTable(DT::datatable({
data <- mpg
if (input$man != "All") {
data <- data[data$manufacturer == "dddddd",]
}
data
},options = list(searching = FALSE,paging = FALSE,callback=DT::JS(
'
{
"language": {
"zeroRecords": "No records to display- custom text"
}}
') )
))
}
shinyApp(ui = ui, server = server)

最佳答案

不使用回调,可以直接使用options参数设置language -> zeroRecords属性:

server <- function(input, output) {
# Filter data based on selections
output$table <- DT::renderDataTable(DT::datatable({
data <- mpg
if (input$man != "All") {
data <- data[data$manufacturer == "dddddd",]
}
data
}, options =
list(searching = FALSE,paging = FALSE,
language = list(
zeroRecords = "No records to display - custom text")
)))
}

这对我有用。

关于javascript - 需要替换 Shiny R renderDataTable 中的默认 "No data available in table"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43984961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com