Return Value out of a Modal Dialog

I'm afraid, I don't understand shiny modules quite right yet.

I have an app with a table that gets its data from a MariaDB server. When the user clicks an actionButton, a modal dialog pops up and displays the underlying query.

I try to handle this and inputs from the modal with this module:

  ### ------------------------------------------------------------------------------------------------
  ### --- Logic For the ACE Editor -------------------------------------------------------------------
  ### ------------------------------------------------------------------------------------------------
  
  
  
  source("./modules/aceUI.R")         # Ace editor embedded in a modal dialog.
  
  
  
  # Launch an instance of the ace editor.
  aceServer <- function(id, query.chr) {
      shiny::moduleServer(
          id
        , function(input, output, session) {
  
              # Show the modal dialog.
              # Other that the usual server/ui build up with modules
              # a modal is dynamic so that its' inputs aren't available
              # even if namespaced correctly.
              aceUI(session$ns, query.chr)
  
              # React to button pushes.
              shiny::observeEvent(
                  input$requery
                  # Return the query edited in the text field.
                , {
                      shiny::removeModal()
                      return(input$sql)
                  }
              )
  
          }
      )
  }

Two problems arise:

  1. When the actionButton is pressed a second time, the modal appears and immediately disappears again.
  2. When the sql query is edited and the actionButton "requery" in the modal dialog is pressed, the changed sql should somehow be returned. But the way I do it, doesn't work. Instead print(aceServer(…)) e.g. just prints info about the function.

This is the modal UI:

### ------------------------------------------------------------------------------------------------
### --- Edit SQL Queries and Statements ------------------------------------------------------------
### ------------------------------------------------------------------------------------------------



# Display a modal dialog with an editor.
aceUI <- function(ns, query.chr) {

    shiny::showModal(
        shiny::modalDialog(
            title = "Query Information"

          , shinyAce::aceEditor(
                outputId = ns("sql")
              , selectionId = ns("selection")
              , value = query.chr
              , placeholder = "Show a placeholder when the editor is empty ..."
              , mode = "sql"
            )

          , easyClose = TRUE
          , fade = TRUE

          , footer = shiny::tagList(
                shiny::modalButton("Dismiss")
              , shiny::actionButton(ns("requery"), "Requery")
            )
        )
    )
}

Help is greatly appreciated.

This topic was automatically closed 54 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.