I have the app. R as following
# load libraries ----
library(shiny)
library(tidyverse)
library(here)
# load data sets ----
daily_metrics_no <- vroom::vroom(here("Data-Files/processed/daily_metrics_no.csv"))
daily_metrics_cent <- vroom::vroom(here("Data-Files/processed/daily_metrics_cent.csv"))
choices <- c("Total_Delivery", "OT", "IF", "OTIF", "None")
ui <- fluidPage(
titlePanel(title = "Supply Chain Analytics Web App"),
tabsetPanel(
tabPanel(
"Introduction",
sidebarLayout( # layouts the app inside bar and main
sidebarPanel(
h2("Introduction"),
p("The purpose of the application is to track and analyze
the Supply Chain Metrics. The application provides a detailed overview
of Supply Metrics by Products, Customers and City. A sperate tab is
made for each category of Analysis."),
br(),
# insert company image
img(src = "StatDevs.png", height = 150, width = 150),
br(),
"The application is developed by ",
span("Stat Devs", style = "color:blue")
),
mainPanel(
h1("Metrics List"),
tableOutput(outputId = "metricstable")
)
)
),
tabPanel("Performance Over Time",
sidebarLayout(
sidebarPanel(
selectInput("metrics", "Metrics", choices = choices,
selected = 1)
),
mainPanel(
plot_UI(id = "metrics")
)
)
),
tabPanel("Products Metrics"),
tabPanel("Customer Metrics"),
tabPanel("City Metrics")
)
)
server <- function(input, output, session) {
# Convert order_placement_date to date format
daily_metrics_no$order_placement_date <- lubridate::ymd(daily_metrics_no$order_placement_date)
# metrics table in Introduction
output$metricstable <- renderTable(metrics)
# Graph in Performance Over Time ----
# collect metric by user
selected_metrics <- reactive({
daily_metrics_no[, input$metrics]
})
observe({
plot_Server(id = "metrics", data = selected_metrics(), date_var = "order_placement_date", y_var = input$metrics)
})
}
shinyApp(ui, server)
I have the plot module as
plot_UI <- function(id) {
ns <- NS(id)
tagList(
fluidRow(
column(11, plotOutput(NS(id, "plot"))),
)
)
}
plot_Server <- function(id, data, date_var, y_var) {
moduleServer(
id,
function(input, output, session) {
output$plot <- renderPlot({
ggplot(data = data, aes(x = as.Date({{ date_var }}), y = {{ y_var }} %>% pull())) +
geom_line() +
labs(x = "Order Placement Date", y = input$metrics)
})
return(output$plot)
}
)
}
plot_demo <- function() {
date <- sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by = "day"), 12)
df <- data.frame(date = date, y_var = 1:12)
ui <- fluidPage(
plot_UI(id = "x")
)
server <- function(input, output, session) {
plot_Server(id = "x", data = df, date_var = "date", y_var = "y_var")
}
shinyApp(ui = ui, server = server)
}
When I type
str(daily_metrics_no$order_placement_date)
it returns:
Date[1:181], format: "2022-03-01" "2022-03-02" "2022-03-03" "2022-03-04" "2022-03-05"
But when I run the shiny application I get the following error in place of the plot.
character string is not in a standard unambiguous format
Can anyone help me why I am getting this error?