Change plotly chart y variable based on selectInput

前端 未结 2 1417
一整个雨季
一整个雨季 2020-12-05 15:04

I\'m creating a simple line chart which renders correctly in Shiny.

I\'ve now added a selectInput with the names of 2 different measures, written as they appear in m

相关标签:
2条回答
  • 2020-12-05 15:16

    Use base::get() function:

    p <- plot_ly(data = data, x = ~Month, y = ~get(input$Measure), type = "line")
    

    or the same using ggplot:

    p <- ggplot(data = data, aes(x = Month, y = get(input$Measure))) +
    geom_line(size = 1.5) + 
    theme_minimal()
    ggplotly(p)
    
    0 讨论(0)
  • 2020-12-05 15:18

    Simply just use data[ ,input$Measure] as Your y variable:

    p <- plot_ly(data = data, x= Month, y = data[ ,input$Measure], type = "line")
    
    0 讨论(0)
提交回复
热议问题