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 =)