我目前正在使用shine为类制作一个应用程序,目前我已经设置了3个单选按钮,并用if-else语句选择它们。我的第一个问题是我的代码无法正常运行,我认为如果我的if-else语句的else部分是问题。此外,如果它能正常运行,我想为每个情节添加字幕。请帮助
ui = function(){
fluidPage(
radioButtons( "type", "", c( "Decomposition", "Seasonality","AFC" )),
plotOutput( "plot" ))
}
server <- function(input, output) {
output$plot <- renderPlot({
req( input$type ) # Plot type required
if( input$type == "Decomposition" )
VOLS %>%
model(classical_decomposition(Interest, type = "multiplicative"))%>%
components()%>%
autoplot()
if(input$type =="Seasonality")
plot(gg_season(VOLS))
else
plot( ggAcf(VOLS) + ggtitle("ACF of VOLS") )
)}
)
shinyApp( ui, server )
您需要用花括号包装if-else语句。
server <- function(input, output) {
output$plot <- renderPlot({
req( input$type ) # Plot type required
if( input$type == "Decomposition" ){
VOLS %>%
model(classical_decomposition(Interest, type = "multiplicative"))%>%
components()%>%
autoplot()
} else if {
plot(gg_season(VOLS))
} else {
plot( ggAcf(VOLS) + ggtitle("ACF of VOLS") )
}
})
}