在图形的弹出窗口中显示字段名称

时间:2019-07-23 07:02:01

标签: r ggplot2 shiny plotly

我配置了上传CSV时的图形显示。用户可以选择字段来配置图形。但是,我想用字段名称替换在弹出窗口中看到的“ get(输入$)”。这是我的功能:

  #-------- REACTIVE DATA --------#
  data <- reactive({
    req(input$csv_chart)
    infile <- input$csv_chart
    if (is.null(infile))
      return(NULL)
    df <- read_csv(infile$datapath)
    updateSelectInput(session, inputId = 'X', label = 'Field X:',
                      choices = names(df), selected = names(df)[1])
    updateSelectInput(session, inputId = 'Y', label = 'Field Y:',
                      choices = names(df), selected = names(df)[2])
    updateSelectInput(session, inputId = 'group', label = 'Group by:',
                      choices = names(df), selected = names(df)[3])
    return(df)
  })


  #-------- PLOT CHART --------#
  output$plot <- renderPlotly({
    ggplot(data()) +
      geom_line(mapping = aes(x = get(input$X), y = get(input$Y), color = as.character(get(input$group)))) +
      labs(x = input$X, y = input$Y, title = "Index Values")
  })

enter image description here

0 个答案:

没有答案