I have a simple shiny module where I want to get the sum from two slider inputs:
The module codes are:
Module
custSliderGroupInput <- function(id,slider1Name,slider2Name){
ns <- NS(id)
tagList(sliderInput(ns("slider1"),slider1Name,1,100,50),
sliderInput(ns("slider2"),slider2Name,1,20,10))
}
custSliderGroup <- function(input,output,session){
rv <- reactiveVal()
observeEvent(c(input$slider1,input$slider2),{
rv <- reactive({input$slider1 + input$slider2})
print(rv())
return(list(result = rv()))
})
}
In my app.R
, I want to display the result on using textOutput
, but it doesn't work and no error is displayed. (the value does get printed in the console though.)
App
library(shiny)
ui <- fluidPage(
custSliderGroupInput("myslider","A","B"),
textOutput("text")
)
server <- function(input, output,session){
output$text <- renderText({
callModule(custSliderGroup,"myslider")$result
})
}
shinyApp(ui = ui, server = server)
I searched on Google and StackOverflow, but all solutions just don't work.