🤷‍♂️ RStudio Addin to Search and Copy Emoji
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

113 lines
3.3KB

  1. #' The ermoji emoji gadget
  2. #'
  3. #' Opens a miniUI based Shiny gadget in the RStudio Viewer pane with a
  4. #' searchable table of emoji. Select a row and click the copy button.
  5. #'
  6. #' @return nothing
  7. #' @export
  8. ermoji_gadget <- function() {
  9. require(shiny)
  10. require(miniUI)
  11. runGadget(ermoji_ui(), ermoji_server, viewer = paneViewer(500), stopOnCancel = FALSE)
  12. }
  13. ermoji_shiny <- function() {
  14. require(shiny)
  15. require(miniUI)
  16. shinyApp(ui = ermoji_ui(), server = ermoji_server)
  17. }
  18. ermoji_ui <- function() {
  19. miniPage(
  20. title = "ermoji",
  21. gadgetTitleBar("ermoji"),
  22. miniContentPanel(
  23. padding = 10,
  24. DT::dataTableOutput('emojis', height = "100%", width = "98%")
  25. ),
  26. miniButtonBlock(
  27. actionButton("copy_name", "Copy :emoji_name:", class = "btn-success"),
  28. actionButton("copy_utf", "Copy Unicode", class = "btn-warning"),
  29. actionButton("copy_gliph", "Copy Emoji", class = "btn-primary")
  30. )
  31. )
  32. }
  33. ermoji_server <- function(input, output, session) {
  34. output$emojis <- DT::renderDataTable({
  35. emojis <- emo::jis
  36. emojis <- emojis[, c('emoji', 'name', "group", "keywords", "aliases")]
  37. emojis$keywords <- purrr::map_chr(emojis$keywords, ~ paste(., collapse = ", "))
  38. emojis$aliases <- purrr::map_chr(emojis$aliases, ~ paste(., collapse = ", "))
  39. DT::datatable(
  40. emojis,
  41. rownames = FALSE,
  42. colnames = c("Emoji", "Name", "Group", "Keywords", "Aliases"),
  43. filter = "top",
  44. selection = "single",
  45. fillContainer = TRUE,
  46. # style = 'bootstrap',
  47. class = 'compact stripe nowrap hover',
  48. options = list(
  49. searchHighlight = TRUE,
  50. search = list(regex = TRUE, caseInsensitive = FALSE),
  51. columnDefs = list(list(
  52. className = "dt-center", targets = 0
  53. )),
  54. pageLength = 10,
  55. lengthMenu = c(4, 5, 10)
  56. )
  57. )
  58. })
  59. this_emoji <- reactive({
  60. req(input$emojis_rows_selected)
  61. as.list(emo::jis[input$emojis_rows_selected, ])
  62. })
  63. this_emoji_name <- reactive({
  64. # name <- this_emoji()$name
  65. name <- this_emoji()$aliases[[1]][1]
  66. paste0(":", gsub(" ", "_", name), ":")
  67. })
  68. this_emoji_uni <- reactive({
  69. uni <- paste0("\\U", this_emoji()$runes)
  70. gsub(" ", "\\\\U", uni)
  71. })
  72. this_emoji_uni_trunc <- reactive({
  73. uni <- this_emoji()$runes
  74. uni <- sub(" .+", "...", uni)
  75. paste0("\\U", uni)
  76. })
  77. observeEvent(input$emojis_rows_selected, {
  78. if (!isTruthy(input$emojis_rows_selected)) {
  79. updateActionButton(session, "copy_name", "Copy :emoji_name:")
  80. updateActionButton(session, "copy_utf", "Copy Unicode")
  81. updateActionButton(session, "copy_gliph", "Copy Emoji")
  82. } else {
  83. updateActionButton(session, "copy_name", paste0("Copy <code>", this_emoji_name(), "</code>"))
  84. updateActionButton(session, "copy_utf", paste("Copy <code>", this_emoji_uni_trunc(), "</code>"))
  85. updateActionButton(session, "copy_gliph", paste("Copy", this_emoji()$emoji))
  86. }
  87. })
  88. observeEvent(input$copy_name, {
  89. clipr::write_clip(this_emoji_name())
  90. })
  91. observeEvent(input$copy_utf, {
  92. clipr::write_clip(this_emoji_uni())
  93. })
  94. observeEvent(input$copy_gliph, {
  95. clipr::write_clip(this_emoji()$emoji)
  96. })
  97. observeEvent(input$done, {
  98. stopApp(invisible())
  99. })
  100. observeEvent(input$cancel, {
  101. stopApp(invisible())
  102. })
  103. }