library(shiny)
counterButton <- function(id, label = "Counter") {
ns <- NS(id)
tagList(
actionButton(ns("button"), label = label),
verbatimTextOutput(ns("out"))
)
}
counterServer <- function(id, ninput) {
moduleServer(
id,
function(input, output, session) {
### Question 1: Can I get here the value of 'nInput'
count <- reactiveVal(ninput)
observeEvent(input$button, {
count(count() + 1)
})
output$out <- renderText({
count()
})
count
}
)
}
ui <- fluidPage(
tabsetPanel(
tabPanel("tab1",numericInput("nInput","Numeric Input",value=10)),
tabPanel("tab2",counterButton("counter1", "Counter #1"))
)
)
server <- function(input, output, session) {
out_from_counter1 <- reactive(
counterServer("counter1",
ninput = req(input$nInput))
)
observeEvent(input$nInput,
{
cat("input$nInput ",input$nInput,"\n")
print(out_from_counter1())
})
### Question 2: Can I get here the value of 'out'?
# the value of out is count from the counterserver
observeEvent(req(out_from_counter1()),
{ofc1 <- out_from_counter1()
cat("out_from_counter1 ",ofc1(),"\n")})
}
shinyApp(ui, server)