Я взял образец набора данных из приведенного выше ответа.
- Преобразование данных из широкоформатного формата в длинный, чтобы можно было фильтровать тип.
- Используйте это для подмножества данных при ggplotting на сервере
library(shiny)
library(tidyverse)
Date <- c("29-Oct-2018", "28-Oct-2018", "27-Oct-2018", "26-Oct-2018")
TypeA <- rnorm(4, 5, 2)
TypeB <- rnorm(4, 5, 3)
TypeC <- rnorm(4, 5, 4)
df <- data.frame(Date = Date, TypeA = TypeA, TypeB = TypeB, TypeC = TypeC)
wide_df <- df %>% gather(Type,Value,2:4)
ui <- fluidPage(
selectInput(inputId = "type",
label = "",
choices = unique(wide_df$Type),
multiple = TRUE),
plotOutput("first_plot")
)
server <- function(input, output, session) {
output$first_plot <- renderPlot({
wide_df %>%
filter(Type %in% input$type) %>%
ggplot() +
geom_point(aes(Date, Value, color = Type))
})
}
shinyApp(ui, server)