Hi, I am extremely new to R and R Shiny (as in a few days.) and I have come across a problem where my R Shiny app is not changing between ggplots when I select the different options in the selectInput drop Down.
library(shiny)
library(plotly)
ui <- fluidPage(
# title
titlePanel("Metric Tracker"),
sidebarLayout(
sidebarPanel(
selectInput("value", "Select Value" , choices = c("Ordered_Product_Sales", "Units_Ordered"), selected = NULL , multiple = FALSE, selectize = TRUE)
),
mainPanel(
plotlyOutput("valuePlot"),
)
)
)
server <- function(input, output) {
name <- reactive({
(input$value)
})
output$valuePlot <- renderPlotly({
if (input$value == name())
metric2 %>%
ggplot(aes(x=Date, y = Ordered_Product_Sales, title = "Sales")) + geom_point() + geom_line( ) + geom_smooth(method = 'lm') + facet_wrap( ~ Brand)
if (input$value == name())
metric2 %>%
ggplot(aes(x=Date, y = Units_Ordered)) + geom_point() + geom_line() + geom_smooth(method = 'lm') + facet_wrap( ~ Brand)
# ggplot(aes(x=metric2$Date, y = metric2[,9])) + geom_point() + geom_line() + geom_smooth(method = 'lm') + facet_wrap( ~ Brand)
})
}
shinyApp(ui = ui, server = server)
Here metric2 is my data set and Ordered_Product_Sales and Units_Ordered are the variables i am trying to plot against the Date. Currently only one of the graphs appears when I run the app, and it doesn't change when another option is chosen.
I am sure I have made a very obvious mistake or there is a way more efficient way, so thanks for your patience.