My module example is running fine but I am getting the error in app.R because of the reactive value for df_metric, how can I make this work?
Any help in this regard is appreciated. The code of the module and app.R is attached below.
I start with helpers.R file where my time_plot function exists
library(tidyverse)
time_plot <- function(df, date_var, y_var) {
ggplot(df) +
aes(
x = .data[[date_var]],
y = .data[[y_var]]
) +
geom_line() +
theme_minimal()
}
source("R/helpers.R")
# plot module ----
plot_UI <- function(id) {
ns <- NS(id)
tagList(
fluidRow(
column(11, plotOutput(NS(id, "plot"))),
)
)
}
plot_Server <- function(id, df, date_var, y_var) {
moduleServer(
id,
function(input, output, session) {
# plot the time series plot
plot <- reactive({time_plot(df, date_var, y_var)})
output$plot <- renderPlot({plot()})
}
)
}
plot_demo <- function() {
df <- data.frame(day = 1:30, arr_delay = 1:30)
ui <- fluidPage(
plot_UI(id = "x")
)
server <- function(input, output, session) {
plot_Server(id = "x", df = df, date_var = "day", y_var = "arr_delay")
}
shinyApp(ui = ui, server = server)
}
My app in app.R looks like
ui <- fluidPage(tabPanel("Performance Over Time",
sidebarLayout(
sidebarPanel(
selectInput("metrics", "Metrics", choices = c("OTIF", "OT", "IF"),
selected = 1)
),
mainPanel(
plot_UI("metrics")
)
)
)
server <- function(input, output, session) {
# metrics table in Introduction
output$metricstable <- renderTable(metrics)
# Graph in Performance Over Time ----
# collect metric by user
df_metric <- reactive({input$metrics})
plot_Server(id = "metrics", df = otif_ot_if_by_day, date_var = "order_placement_date", y_var = df_metric)
}
shinyApp(ui, server)
I am also attaching a snap shot of the error in Shiny App.
The error says the following in R console
Warning: Error in geom_line: Problem while computing aesthetics.
Error occurred in the 1st layer.
Caused by error in FUN()
:
! Unknown input:
! Unknown input: