【问题标题】:R update select input values from csv file data valuesR更新从csv文件数据值中选择输入值
【发布时间】:2015-10-01 10:38:03
【问题描述】:

KPIFile 文件将由用户在 fileinput 小部件中上传。

KPIFile 有两列 From 和 To。我正在尝试使用 updateselect 输入函数将 To 列的值加载到选择输入中。它没有从 TO 列加载值,而是加载了一些数字。

# Loading the KPI data

KPI <- reactive({
    KPIFile<-input$KPI

    if(is.null(KPIFile))
      return(NULL)

     read.csv(KPIFile$datapath, header=input$header, sep=input$sep, 
             quote=input$quote)
    })


 #Loading the X and Y axis
 observe({

   updateSelectInput(session,"XVal", choices = KPI()[2])
   updateSelectInput(session,"YVal", choices =KPI()[2])


 })

【问题讨论】:

  • 我的回答对你有用吗?如果是,请接受!
  • 没有。我仍然得到随机数。我的 CSV 文件内容如下所示。从 到 EHRDKRS KB 读取/秒 EHRDKWS KB 写入/秒 EAAR 应用程序重新启动 EAARu 应用程序运行 EAAA 应用程序可用性 EAMA 机器可用性。 OAPWECPM EHL 呼叫/分钟
  • 请包含整个 csv

标签: r shiny shiny-server


【解决方案1】:

如果没有给您带来麻烦的csv 文件,就很难说出了什么问题。我的猜测是R 正在将该列转换为factor

为防止这种情况发生,请在函数中使用stringAsFactors = FALSE 来读取csv 文件

read.csv(KPIFile$datapath, header=input$header, sep=input$sep, 
         quote=input$quote, stringAsFactors = FALSE)

或者之后用

进行转换
 yourDataFrame$columnYouNeedToRead <- as.factor(yourDataFrame$columnYouNeedToRead)

或(相同)

library(magrittr)
yourDataFrame$columnYouNeedToRead %<>% as.character

【讨论】:

  • @VinothLoganathan 很高兴听到。如果你喜欢这个答案,请接受它:) 这就是 SO 的工作原理
猜你喜欢
  • 2014-02-25
  • 2017-03-02
  • 1970-01-01
  • 1970-01-01
  • 2021-09-23
  • 2013-02-11
  • 1970-01-01
  • 2018-09-23
  • 1970-01-01
相关资源
最近更新 更多