[英]ggplotly in shiny app keeps crashing (Rstudio)
我试图在一个闪亮的应用程序中渲染一个 ggplotly,但我的代码甚至没有运行。 任何帮助都非常感谢! 我在哪里犯了错误? 我对 R 很陌生。请参阅下面的代码。
**
ui <- fluidPage(
titlePanel("Plotly"),
sidebarLayout(
sidebarPanel(),
mainPanel(
plotlyOutput("plot2"))))
server <- function(input, output) { output$plot2 <- renderPlotly(print(
ggplotly(
q<-ggplot(plotdata,aes(x=DateValue, y=Count, col=Country,
group=1
))+
geom_line(aes(text=paste
( '<br>Number of Launches:', Count,
'<br>Country:', Country)
))
+
scale_colour_manual(values = c('yellow','orange','turquoise1','mediumspringgreen','tan3','indianred4','plum1','slateblue2','violetred2','greenyellow','blue1','black','firebrick2'))+
theme( axis.line = element_line(colour = "black",
size = 1, linetype = "solid"))+
scale_x_continuous(breaks=c(1945,1955,1965,1975,1985,1995,2005,2015,2025))+
scale_y_continuous(breaks=c(0,20,40,60,80,100,120))+
theme_bw()+
guides(colour = guide_legend(override.aes = list(shape = 3))) +
labs(title="Space Launches per Year",
subtitle="Colored by country",
caption="Source: ...",
y="Number of Launches",
x="Year")),
ggplotly(q, tooltip = "text"))}}
**
如下所示更改您的服务器代码,并确保您有一个名为plotdata
的数据plotdata
进行绘图。 不需要初始print
语句。 另外,您在 ggplotly 中调用了 ggplotly。
server <- function(input, output) {
output$plot2 <- renderPlotly({
q<-ggplot(plotdata,aes(x=DateValue, y=Count, col=Country, group=1))+
geom_line(aes(text=paste
( '<br>Number of Launches:', Count,
'<br>Country:', Country))) +
scale_colour_manual(values = c('yellow','orange','turquoise1','mediumspringgreen','tan3','indianred4','plum1','slateblue2','violetred2','greenyellow','blue1','black','firebrick2'))+
theme( axis.line = element_line(colour = "black",
size = 1, linetype = "solid"))+
scale_x_continuous(breaks=c(1945,1955,1965,1975,1985,1995,2005,2015,2025))+
scale_y_continuous(breaks=c(0,20,40,60,80,100,120))+
theme_bw()+
guides(colour = guide_legend(override.aes = list(shape = 3))) +
labs(title="Space Launches per Year",
subtitle="Colored by country",
caption="Source: ...",
y="Number of Launches",
x="Year")
ggplotly(q, tooltip = "text")
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.