我一直在尝试使用DT开发R Shiny Webapp来显示数据表。我需要使用输入来填充数据表搜索选项,因为我正在按term-freq筛选和排序可能的搜索词。我的数据是法文,因此包含带有latin1编码的重音(我尝试使用UTF8编码,但是渲染变得凌乱)。
我比较了服务器端计算和客户端计算中的renderDataTable行为。客户端工作良好,但数据量很大,需要通过这种方式进行处理。服务器端找不到重音词(法语重音)的匹配项。
这是一个repex
library(shiny)
library(DT)
data=data.frame(index=1:6,nom=c("hého","bonjour","enchanté","merci","où ça ?","à qui s'adresse-t-il ?"),stringsAsFactors = F)
ui <- fluidPage(
title = 'Use the DT package in shiny',
selectizeInput(inputId = 'tag',label="mots pour filtrer",
choices=strsplit(data$nom,split = " ")%>%unlist%>%unique),
h3('A Table Using Client-side Processing'),
fluidRow(
DT::dataTableOutput('tbl_a')
),
h3('A Table Using Server-side Processing'),
fluidRow(
DT::dataTableOutput('tbl_b')
)
)
server <- function(input, output, session) {
output$tbl_a = DT::renderDataTable(datatable(data,options=list(search=list(search=input$tag))), server = FALSE)
output$tbl_b = DT::renderDataTable(datatable(data,options=list(search=list(search=input$tag))))
}
shinyApp(ui,server)
Run Code Online (Sandbox Code Playgroud)
客户端处理返回期望的结果...但是我想通过服务器端处理来实现。
这是对的调用的输出 xfun::session_info('DT')
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running …Run Code Online (Sandbox Code Playgroud)