Last active
February 22, 2022 19:11
-
-
Save cecilialee/e848068cfd5862fd63961b03b42ead78 to your computer and use it in GitHub Desktop.
Use icons in DT datatable in Shiny. #r #shiny #dt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(DT) | |
library(dplyr) | |
ui <- basicPage( | |
DT::dataTableOutput("table") | |
) | |
server <- function(input, output, session) { | |
output$table <- DT::renderDataTable({ | |
data <- mtcars %>% | |
mutate(icon = as.character(icon("tag", lib = "glyphicon"))) | |
datatable(data, escape = FALSE) | |
}) | |
} | |
shinyApp(ui, server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(DT) | |
library(dplyr) | |
ui <- basicPage( | |
DT::dataTableOutput("table") | |
) | |
server <- function(input, output, session) { | |
gicon <- function(x) as.character(icon(x, lib = "glyphicon")) | |
output$table <- DT::renderDataTable({ | |
status <- c("new", "entered", "skipped", "issue", "validated", "removed") | |
icon <- c(gicon("pencil"), gicon("ok"), gicon("remove"), gicon("alert"), gicon("flag"), gicon("trash")) | |
datatable(cbind(status, icon), escape = FALSE) | |
}) | |
} | |
shinyApp(ui, server) |
This has been wicked helpful. Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Me to, thanks for this short and effective example