Hi, I am working on a shiny project with modules (golem framework), and I tried implementing the example here:
I can get that working no problem as a single file. I'm a little out of my depth here, but here's how I make that into a module:
#' temp_bar_plot UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
#'
mod_temp_bar_plot_ui <- function(id){
ns <- NS(id)
tagList(
fluidPage(
selectInput("territory", "Territory", choices = unique(sales$TERRITORY)), selected = "NA",
selectInput("customername", "Customer", choices = NULL),
selectInput("ordernumber", "Order number", choices = NULL),
tableOutput("data")
)
)
}
#' temp_bar_plot Server Functions
#'
#' @noRd
mod_temp_bar_plot_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
territory <- reactive({
filter(sales, TERRITORY == input$territory)
})
observeEvent(territory(), {
choices <- unique(territory()$CUSTOMERNAME)
updateSelectInput(inputId = "customername", choices = choices)
})
customer <- reactive({
req(input$customername)
filter(territory(), CUSTOMERNAME == input$customername)
})
observeEvent(customer(), {
choices <- unique(customer()$ORDERNUMBER)
updateSelectInput(inputId = "ordernumber", choices = choices)
})
output$data <- renderTable({
req(input$ordernumber)
customer() %>%
filter(ORDERNUMBER == input$ordernumber) %>%
select(QUANTITYORDERED, PRICEEACH, PRODUCTCODE)
})
})
}
## To be copied in the UI
# mod_temp_bar_plot_ui("temp_bar_plot_ui_1")
## To be copied in the server
# mod_temp_bar_plot_server("temp_bar_plot_ui_1")
sales
is loaded at runtime. I get this error:
Warning: Error in : Problem with `filter()` input `..1`.
ℹ Input `..1` is `TERRITORY == input$territory`.
x Input `..1` must be of size 2823 or 1, not size 0.
[No stack trace available]
It doesn't like the first call of the first reactive in the observeEvent
. I thought the Hadley's discussion of freezing reactive inputs might help, but no luck. This would be a great workflow if I could get it to work!
Thanks for all the help!