选择输入选项是文件输入.csv文件列的唯一值

时间:2018-02-19 21:46:35

标签: r shiny selectinputdate

我正在尝试开发一个闪亮的App,其中y轴变量将是上传的.csv文件中列的唯一值。 Sp,我可以读取列名并在selectInput中设置为选项,但不能列为列的唯一值。我的阅读和选择列的代码是

    library(shiny)

myData <- NULL
ui <- fluidPage(

  titlePanel("My R Shiny App"),

  sidebarPanel(

    fileInput(
      'file', 
      'Choose file to upload.'
    ),

    selectInput(
      "y_input", 
      label = h5("Select Time Series/Response Variable"),
      ""
    )

  )

)

server <- function(input, output, session) {

  inFile <- reactive({
    if (is.null(input$file)) {
      return(NULL)
    } else {
      input$file
    }
  })

  myData <- reactive({
    if (is.null(inFile())) {
      return(NULL)
    } else {
      read.csv(inFile()$datapath)
    }
  })

  observe({
    updateSelectInput(
      session,
      "y_input",
      choices=names(myData()))

  })

}
shinyApp(ui=ui, server=server)

数据集例如:

Geography   Measure Time    Value
abc Meause A    2011    4
abc Meause A    2012    5
abc Meause B    2013    6
cba Meause B    2014    7
cba Measure C   2015    8
cba Measure C   2016    9
bac Meause A    2011    10
bac Meause A    2012    4
bac Meause B    2013    5
abc Meause B    2014    6
cba Measure C   2015    7
bac Measure C   2016    8

对于y轴选择,我想要列Geography的唯一值,即abc,cba,bac。任何想法和建议。

0 个答案:

没有答案