I want to have an application which plots my data in different types (as Line, as dots, as boxplot).
Let's consider my code :
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)
And I'm not sure what sure I put in server to be able to switch between these different types. I tried to use if statement and get(input$type) but both options give me nothing more than errors.
To summarize - How can I write my application so that I can switch between different plot types (Line, Dots, Boxplot) as shown in image ?
