0

我正在尝试开发一个闪亮的应用程序,其中 y 轴变量将是上传的 .csv 文件中列的唯一值。Sp far,我可以读取列名并将其设置为 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 轴选择,我想要地理列的唯一值,即 abc、cba、bac。任何想法和建议。

4

0 回答 0