shinyshinybs

Shiny bsModal: Possible to remove the x close button in title?


I have my Shiny bsModal setup as so:

# ui.R
bsModal("test_events_modal", htmlOutput("modal_title"), trigger='dummy', size = "large",
  div(dataTableOutput("current_test_events_dt"), style = "font-size:90%;width:95%")
)

# server.R
modal_title = glue('EVENT HISTORY: {selected_flow_context}') 
output$modal_title <- renderUI({ span(tagList(icon("timeline"), modal_title)) })
toggleModal(session, 'test_events_modal', toggle = "toggle")

This produces:

enter image description here

I would like the title text to be left aligned and would like to remove the annoying and redundant 'x' widget as the bsModal object has a close button.

thx


Solution

  • We can use htmltools::tagQuery to achive this.

    As your code isn't reproducible I've adapted this example:

    library(shiny)
    library(shinyBS)
    library(htmltools)
    
    shinyApp(
      ui =
        fluidPage(
          sidebarLayout(
            sidebarPanel(
              sliderInput("bins",
                          "Number of bins:",
                          min = 1,
                          max = 50,
                          value = 30),
              actionButton("tabBut", "View Table")
            ),
            
            mainPanel(
              plotOutput("distPlot"),
              tagQuery(bsModal("modalExample", "Data Table", "tabBut", size = "large",
                               dataTableOutput("distTable")))$find("button")$addAttrs("style" = "display:none;")$allTags()
            )
          )
        ),
      server =
        function(input, output, session) {
          
          output$distPlot <- renderPlot({
            
            x    <- faithful[, 2]
            bins <- seq(min(x), max(x), length.out = input$bins + 1)
            
            # draw the histogram with the specified number of bins
            hist(x, breaks = bins, col = 'darkgray', border = 'white')
            
          })
          
          output$distTable <- renderDataTable({
            
            x    <- faithful[, 2]
            bins <- seq(min(x), max(x), length.out = input$bins + 1)
            
            # draw the histogram with the specified number of bins
            tab <- hist(x, breaks = bins, plot = FALSE)
            tab$breaks <- sapply(seq(length(tab$breaks) - 1), function(i) {
              paste0(signif(tab$breaks[i], 3), "-", signif(tab$breaks[i+1], 3))
            })
            tab <- as.data.frame(do.call(cbind, tab))
            colnames(tab) <- c("Bins", "Counts", "Density")
            return(tab[, 1:3])
            
          }, options = list(pageLength=10))
          
        }
    )