🤷‍♂️ RStudio Addin to Search and Copy Emoji
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

105 Zeilen
3.2KB

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