【发布时间】:2020-12-22 08:45:43
【问题描述】:
我想要一个应用程序来绘制不同类型的数据(如线、点、箱线图)。
让我们考虑一下我的代码:
library(shiny)
library(quantmod)
start <- as.Date("2013-01-01")
end <- as.Date("2016-10-01")
# Apple stock
getSymbols("AAPL", src = "yahoo", from = start, to = end)
apple <- AAPL$AAPL.Close
### Define UI for application
ui <- fluidPage(
# Sidebar panel
sidebarPanel(
selectInput("type",
label = "1. Select plot type",
choices = c("Line" = "geom_line()", "Dot" = "geom_point()", "Boxplot" = "geom_boxplot()"),
selected = 3
)
),
# Main Panel
mainPanel(
plotOutput("sp")
)
)
server <- function(input, output) {
output$sp <- renderPlot({
colm <- as.numeric(apple)
ggplot() +
aes(x = 1:length(colm), y = colm) +
geom_line() +
xlab(NULL)
})
}
# Run the application
shinyApp(ui = ui, server = server)
而且我不确定我在server 中输入了什么才能在这些不同类型之间切换。我尝试使用if 语句和get(input$type),但这两个选项都给我带来了错误。
总结 - 我如何编写我的应用程序,以便可以在不同的绘图类型(线、点、箱线图)之间切换,如图所示?
【问题讨论】: