在 R shiny 中打印数据表时编码错误

bad encoding with printing a datatable in R shiny

首先,抱歉我的英语不好,因为我不是说英语的人。这导致了我的问题,在我的语言中,我们使用重音和其他特定字符。 我需要在闪亮的数据 table (renderDataTable) 上打印 data.frame,并且某些重音符号打印不正确。 Exemple of lines bas printed, eg 10, 11, 12, 13, 14

这是我的代码,灵感来自于 Rshiny 网站,参考 renderDataTable:

.libPaths("C:/R_library")
library(shiny)
niveau3 <- read.csv2("Libelle_NC.txt", encoding="UTF-8", header = FALSE, sep = ";", na.strings = "", stringsAsFactors = TRUE)

ui <- fluidPage(
    fluidRow(
        column(12,
               dataTableOutput("table"),
        )
    )

)

server <- function(input, output) {

    output$table <- renderDataTable(
        {
             niveau3
        },
        options = list(
            pageLength = 15,
            initComplete = I("function(settings, json) {alert('Done.');}")
        )
    )

    output$tableAsiat <- renderDataTable({
        asiat
    })
}

shinyApp(ui= ui , server=server)

文件 Libelle_NC.txt 可以在 link towards data gouvernement of exportation/importation

的第一个 zip 中找到

问题是显示的线条似乎不规则: 例如渲染的第 9 行 table 正确打印“...(à...”但第 10 行不正确。

我在 jQuery DataTable 页面的选项参考 link 上寻找要在函数 renderDataTableoptions=list() 部分编码的选项。 而且我没有找到任何关于编码的选项。

我认为这是由于 read.csv 函数没有正确编码,但 View(niveau3) 显示印刷良好 data.frame。

renderDataTable() 的编码是否有任何操作或选项,或者我应该在打印过程之前处理 data.frame?

谢谢。

不确定这是否可行,但您可以尝试使用 niveau3$V2 <- enc2native(niveau3$V2)

重新编码 V2

取自:

http://shiny.rstudio.com/articles/unicode.html