Reactivity within Shiny module not working

Hi, I am really struggling with getting basic reactivity working within a Shiny module. Below, I've copied the module that I'm using. When I run this, the output shows for the initial value of the input, but doesn't update when I change the input. I'm hoping this is a really easy fix because it's such a simple thing I'm trying to do.

I've read the documentation for Shiny modules as well as about 30 Q&As on stack overflow and this site. Nothing has worked so far. Any help would be hugely appreciated!

mod_user_feedback_ui <- function(id) {
  ns <- NS(id)
  tagList(
    numericInput(
      inputId = ns('n'),
      label = 'Select an even number',
      value = 1
    ),
    shiny::textOutput(ns('half'))
  )
}

mod_user_feedback_server <- function(id) {
  moduleServer(id, function(input, output, session) {
    ns <- session$ns
    
    half <- reactive({
      paste0('Half:', input$n / 2)
    })
    
    output$half <- shiny::renderText(half())
  })
}

it works for me on shiny 1.6.0.

library(shiny)

mod_user_feedback_ui <- function(id) {
  ns <- NS(id)
  tagList(
    numericInput(
      inputId = ns('n'),
      label = 'Select an even number',
      value = 2
    ),
    shiny::textOutput(ns('half'))
  )
}

mod_user_feedback_server <- function(id) {
  moduleServer(id, function(input, output, session) {

    half <- reactive({
      paste0('Half:', input$n / 2)
    })
    
    output$half <- shiny::renderText(half())
  })
}

ui <- fluidPage(
  mod_user_feedback_ui("test_1")
)

server <- function(input, output, session) {
  
  mod_user_feedback_server("test_1")
}

shinyApp(ui, server)
1 Like

nirgrahamuk - Thank you very much for trying this out. Running that code also works for me but my app is in reality more complicated, with a number of different tabs and modules.

I have now solved my issue though, which was that I was using a submitButton on a different tab/module that was apparently shutting down all reactivity in all tabs/modules. I just removed the submitButton as it wasn't really essential for me.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.