Hello guys!
I'm facing an issue with architecting the main server module to effectively listen for calls from the smodData
module triggered within the smodUserInpt
module.
My current output is: [1] "Drawing..." [1] 619 [1] "Drawing..."
But I expect: [1] "Drawing..." [1] 619 [1] "Drawing..." [1] 324
I understand that a simpler solution might exist by adjusting the logic, but I specifically need the listening capability in this scenario since the actual use case is more intricate.
The code:
library(shiny)
###################################################### Module 1
smodData <- function(id, default) {
moduleServer(id, function(input, output, session) {
print("Drawing...")
return(sample(1:1000, 1))
})
}
###################################################### Module 2
umodUserInpt <- function(id) {
ns <- NS(id)
tagList(
actionButton(
inputId = ns("button"),
label = "Click"
)
)
}
smodUserInpt <- function(id, default) {
moduleServer(id, function(input, output, session) {
observeEvent(input$button, {
smodData("m1")
})
})
}
####################################################### Main
server <- function(input, output, session) {
smodUserInpt("m2")
observe({
x <- smodData("m1")
print(x)
})
}
ui <- fluidPage(
umodUserInpt("m2")
)
shinyApp(ui = ui, server = server)
I apologize in advance if I'm duplicating the topic, but I couldn't find a similar scenario/function :(.