How can I add background color and icon in title of modalDialog() function in R shiny?

I am using the following code.

library(shiny)
library(dplyr)
library(DT)

app <- shinyApp(
  ui = fluidPage(
    
    DT::dataTableOutput("mydatatable")
  ),
  
  server =  shinyServer(function(input, output, session) {
    
    mycars <- reactive({ head(mtcars)})
    output$mydatatable = DT::renderDataTable(mycars(), selection = 'single',  
                                             rownames = FALSE, options = list(dom = 't'))
    selected_row <- reactiveVal(value = NULL)
    observeEvent(input$mydatatable_rows_selected,{
      selected_row(input$mydatatable_rows_selected)
    })
    
    observeEvent(selected_row(), {
      showModal(modalDialog(
        title = 'adding bg color and icon',
        tags$div(HTML(paste(
          "cyl = ",
          tags$span(mycars()$cyl[selected_row()],
                    style = paste("color:", if (mycars()$mpg[selected_row()] > 21) {
                      "red"
                    } else {
                      "blue"
                    })
          )
        )))
      ))
    })
  })
)

app

My aim is to change background color of title similar to the color I have for cyl value in modalDialog() and also to add a robot icon in the title if cyl <= 6 and a user icon if cyl > 6, like below picture.

How is it possible in R shiny? Thanks in advance =)

1 Like

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.