Shiny App中的R charToRaw和enc2utf8问题

时间:2016-05-30 08:41:29

标签: r shiny

我正在使用

将带有三列的cvs文件读入数据框
proj_epsg <- data.frame(read.csv('file.csv', encoding = 'UTF-8')

并获取三个列中的两列作为选择框的输入

epsg_choices <- setNames(as.numeric(proj_epsg$EPSG), as.character(proj_epsg$Name))

当我运行应用程序时,控制台将填充类型为

的警告
Warning in charToRaw(enc2utf8(text)) :
  argument should be a character vector of length 1
all but the first element will be ignored

因此,我尝试用UTF-8编码读取数据。我还用UTF-8保存了cvs文件,将编码从ASCII更改为UTF-8。

如何在没有警告的情况下获得正确的charToRaw结果?

1 个答案:

答案 0 :(得分:0)

好的,我找到了一个解决方案,但我对此并不满意......

在ui.R文件中,我定义了htmlOutput

htmlOutput(selectInProj')

并在server.R文件中编写了以下函数

function(input, output) {
  proj_epsg <- data.frame(read.csv('file.csv', encoding = 'UTF-8'))
  eps_choices <- setNames(as.numeric(proj_epsg$EPSG), as.character(proj_epsg$Name)
  output$selectInProj <- renderUI({
    selectInput('in_start', label = h4('Projection start points'), epsg_choices)
  })
}

它有效,没有关于编码的警告,并且Selectbox正在获得正确的输入。但是,renderUI现在需要一段时间,因为cvs fiel包含超过5000行。

之前可以创建SelectBoxes的内容,因此用户不必等待那么久。

有任何建议吗?