我目前正在与 Rshiny 合作创建一个交互式应用程序。我处理一个问题:我有一个 selectInput(Nom) 允许我在运动员列表中选择一个名字,下面有这个图,显示了我所有运动员的值。我试图在保留整个情节的同时突出所选运动员的价值观。我对所有想法持开放态度,因为我没有找到任何令我信服的解决方案。我在当前的绘图上附加了一个屏幕。如果有人有办法突出显示我的 selectInput 选择的运动员价值观,同时保留我的整个情节,我将不胜感激。谢谢!
Data_GPS_G3_filtre <- reactive({
Donnees_globales |>
filter(Nom == input$Nom)
})
[...]
output$highlightedPlot <- renderPlot({
colors <- ifelse(Data_GPS_G3_filtre$Nom == input$Nom, "yellow", scales::col_numeric(c("red", "lightgreen"), domain = NULL)(Data_GPS_G3_filtre$RM_Relatif))
plot_1 <- ggplot(data = Data_GPS_G3_filtre()) +
aes(x = RM_Relatif, y = Nom, fill = RM_Relatif) +
geom_col(color = "black", position = "stack") +
geom_text(aes(label = ifelse(RM_Relatif == 0, "", RM_Relatif)), color = "black", position = position_stack(vjust = 0.5)) +
facet_grid(cols = vars(Mouvements_performances)) +
theme(plot.background = element_rect(fill = "white"),
panel.background = element_rect(fill = "white"),
panel.grid = element_blank(),
panel.border = element_blank()) +
scale_fill_manual(values = colors)
colours <- ifelse(Data_GPS_G3_filtre$Nom == input$Nom, "yellow", scales::col_numeric(c("red", "lightgreen"), domain = NULL)(Data_GPS_G3_filtre$Valeur_Absolu))
plot_2 <- ggplot(data = Data_GPS_G3_filtre()) +
aes(x = Valeur_Absolu, y = Nom, fill = Valeur_Absolu) +
geom_col(color = "black", position = "stack") +
geom_text(aes(label = ifelse(Valeur_Absolu == 0, "", Valeur_Absolu)), color = "black", position = position_stack(vjust = 0.5)) +
facet_grid(cols = vars(Absolu)) +
theme(plot.background = element_rect(fill = "white"),
panel.background = element_rect(fill = "white"),
panel.grid = element_blank(),
panel.border = element_blank()) +
scale_fill_manual(values = colours)
fig_group <- ggpubr::ggarrange(plot_1, plot_2)
return(fig_group)
})
我会为没有颜色的图做一个电抗导体:
Plot1 <- reactive({
ggplot(data = Data_GPS_G3_filtre()) +
aes(x = RM_Relatif, y = Nom, fill = RM_Relatif) +
geom_col(color = "black", position = "stack") +
geom_text(aes(label = ifelse(RM_Relatif == 0, "", RM_Relatif)), color = "black", position = position_stack(vjust = 0.5)) +
facet_grid(cols = vars(Mouvements_performances)) +
theme(plot.background = element_rect(fill = "white"),
panel.background = element_rect(fill = "white"),
panel.grid = element_blank(),
panel.border = element_blank())
})
output$highlightedPlot <- renderPlot({
colors <- ifelse(Data_GPS_G3_filtre$Nom == input$Nom, "yellow", scales::col_numeric(c("red", "lightgreen"), domain = NULL)(Data_GPS_G3_filtre$RM_Relatif))
Plot1() + scale_fill_manual(values = colors)
})
这样,每次
input$Nom
变化时,绘图就不会完全重建。