我尝试使用 Plotly 以闪亮的方式执行此操作,但没有如上所示的图层。虽然这可能是一个旧线程,但它可能对其他人有帮助。
在以下示例中:
- 首先根据一个人的分数显示一个情节。
- 然后,当我们从列表中选择输入时,其他人的其他分数会在同一图上更新。
library(shiny)
library(plotly)
ui <- fluidPage(
selectizeInput(
inputId = "Player",
selected = NULL,
multiple = TRUE,
label = " Choose Player",
choices = c("Sam", "Bennet", "Orlando"),
options = list('plugins' = list('remove_button'))
),
plotlyOutput("Plot1")
)
server <- function(input, output, session) {
output$Plot1 <- renderPlotly({
scores <- data.frame(Name = c("Sam", "Bennet", "Orlando", "Sam", "Bennet", "Orlando", "Sam", "Bennet", "Orlando" ),
Number= c(47, 35, 40, 49, 32, 31, 51, 49, 44 ),
Year = c("2018","2018","2018", "2017", "2017", "2017", "2016","2016","2016")
)
chris_goals <- data.frame(Name = c("Chris", "Chris", "Chris"),
Number= c(90, 95, 100 ),
Year = c("2018","2017","2016")
)
filteredScores <- reactive({
plot_ly(chris_goals, x = ~Year, y = ~Number, type = 'scatter', mode = 'lines', color = ~Name)%>% layout(showlegend = TRUE) %>%
layout(title = 'Scores') %>%
add_trace(data = scores[scores$Name %in% input$Player, ], x = ~Year, y = ~Number, type = 'scatter', mode = 'lines', color = ~Name)
})
filteredScores()
})
}
shinyApp(ui, server)
默认值: