![](/img/trans.png)
[英]Unknown issue in aesthetics breaks down ggplotly plot in a shiny app
[英]ggplotly not working in shiny app, plot not showing up
我目前正在制作 Shiny 应用程序,我尝试使用此图(在服务器中使用):
output$COTY_out1 <- renderPlot({
data %>%
group_by(year) %>%
summarize(mean_ls = mean(life_satisfaction, na.rm = TRUE)) %>%
ggplot(mapping = aes(x = year, y = mean_ls)) +
geom_line() +
geom_smooth() +
labs(y = "Mean Life Satisfaction", x = "Year", title = "World")
})
这在应用程序中显示得很好!
现在,我尝试在其中集成 plotly 并基本上从工作应用程序中复制了这段代码。 我还查阅了堆栈并找到了类似的答案。
output$COTY_out1 <- renderPlotly({
p <- data %>%
group_by(year) %>%
summarize(mean_ls = mean(life_satisfaction, na.rm = TRUE)) %>%
ggplot(mapping = aes(x = year, y = mean_ls)) +
geom_line() +
geom_smooth() +
labs(y = "Mean Life Satisfaction", x = "Year", title = "World")
p <- ggplotly(p)
p
})
但是,执行此操作后,图表不会显示。 我集成 ggplotly 的方式有问题吗? 就像我之前说的,我在这个论坛上看了类似的答案,基本上试图复制粘贴很多都无济于事。
我最终通过一些实验找到了解决方案!
output$COTY_out1 <- renderPlotly({
data %>%
group_by(year) %>%
summarize(mean_ls = mean(life_satisfaction, na.rm = TRUE)) %>%
ggplot(mapping = aes(x = year, y = mean_ls)) +
geom_line() +
geom_smooth() +
labs(y = "Mean Life Satisfaction", x = "Year", title = "World")
})
确保在 UI 中使用plotlyOutput
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.