# Module UI
#' @title mod_index_chooser_ui and mod_index_chooser_server
#' @description A shiny Module that provides a dynamically filled dropdown list of Elasticsearch indexes
#'
#' @param id shiny id
#' @param input internal
#' @param output internal
#' @param session internal
#' @param esConn Elasticsearch connection object
#' @param prefix the prefix to filter the list of ES indexes by
#'
#' @rdname mod_index_chooser
#'
#' @keywords internal
#' @export
#' @importFrom shiny NS tagList
mod_index_chooser_ui <- function(id){
ns <- NS(id)
tagList(
selectInput(ns("indexName"), "Choose index:", choices = c("")),
)
}
# Module Server
#' @rdname mod_index_chooser
#' @export
#' @keywords internal
mod_index_chooser_server <- function(input, output, session, allIndices, prefix){
ns <- session$ns
observe({
indexNames <- Filter(function(s) grepl(prefix, s), names(allIndices))
defaultIndex <- ifelse(esDefaultIndex %in% indexNames, esDefaultIndex, "")
selected <- ifelse(input$indexName == "", defaultIndex, input$indexName)
updateSelectInput(session, "indexName",
choices = indexNames,
selected = selected)
})
return(reactive(input$indexName))
}
## To be copied in the UI
# mod_index_chooser_ui("index_chooser_ui_1")
## To be copied in the server
# callModule(mod_index_chooser_server, "index_chooser_ui_1")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.