Best way to provide Generic Support

Hi - First post !

I have a function create UI help buttons by id
and a function invoked from within sever when corresponding id is clicked

Global.R

library(shiny)

#'' Create button input for Help (classed help for .css)
#' @param id The inputId for the help button
#' @label label for help button
help_ui <- function(id, label){
  actionButton(inputId = id,  label=label, icon = icon("info-circle"), class="help")
}

#' Show modal help file corresponding to input name
#' @param ref - Name of an input$ref
showHelp <- function(ref){

# Define a help file where we keep markdown docs
  f <- paste0("./doc/en/", ref)
# Define a fall back if help files have not been maintained
  if(!file.exists(f))
    f <- paste0("./doc/en/", "missing_help.md")
# Display help 
  showModal(
    modalDialog(
      includeMarkdown(f),
    easyClose=TRUE, size= "l"
  ))
}

I define help buttons within UI.R as follows

shinyUI(fluidPage( # flexible layout function
  
  # Title
  titlePanel("Minimal application"),
  
  sidebarLayout(  # standard inputs on sidebar, outputs in main area layout
    sidebarPanel( # sidebar configuration

     help_ui("sidebar.md", label = "Menu Help"),

      textInput(inputId = "comment",      # this is the name of the
                # variable- this will be passed to server.R
                label = "Say something?", # display label for the variable
                value = ""                # initial value
      )),
    
    # Show a plot of the generated distribution
    mainPanel( # main output configuration
      h3("This is you saying it"), # title with HTML helper
      help_ui("display.md", label = "What to expect"),
      textOutput("textDisplay")    # this is the name of the output
      # element as defined in server.R
    )
  )
))

And have corresponding observrs to throws up modal help when wanted

Server.R

library(shiny) # load Shiny at the top of both scripts


shinyServer(function(input, output) { # define application in here

  output$textDisplay <- renderText({ # mark function as reactive
    # and assign to output$textDisplay for passing to ui.R
    
    paste0("You said '", input$comment,           # from the text
           "'. There are ", nchar(input$comment), # input control as
           " characters in this.")                # defined in ui.R
    
  }

  observeEvent(input$display.md, showHelp("display.md"))
  observeEvent(input$sidebar.md, showHelp("sidebar.md"))
  # Many more help texts here...
)

Finally I have simple help texts in markdown

Eg. ./doc/en/missing_help.md"

# Apologies - This help file is undergoing maintenance
This is horribly unhelpful but a mistake - so we have logged the error and will act soon

Eg ./doc/en/sidebar.md

# Navigation help
Click on stuff !

My Question

I would like to replace the many obervers with one generic for input ids that are the same name as a markdown file

#  Replace  these 
observeEvent(input$FILENAME.md, showHelp("FILENAME.md"))

(of which there are very many) with something generic

observe{
    # Define values of input that have ".md in their name"
    isolate({
      input_defs <- reactiveValuesToList(input)
      the_names = names(input_defs)
      help_inputs = grep(".md", the_names, value = TRUE )

    # Excuse for loop its just easy to grasp  help.md is a variable holding some input$`whatever.md` 
    for (help.md in help_inputs) {

      # Select input button that has been incremented ( if any )
       if(  LOGIC NEEDED <help.md was clicked>  )   showHelp(help.md)
    }
}

Any help greatfully received (and a completely different approach also welcomed)