Sfoglia il codice sorgente

Split ui/server and add ermoji_shiny()

tags/v0.1.1
Garrick Aden-Buie 8 anni fa
parent
commit
111c9e21b3
1 ha cambiato i file con 82 aggiunte e 74 eliminazioni
  1. +82
    -74
      R/ermoji_gadget.R

+ 82
- 74
R/ermoji_gadget.R Vedi File

@@ -8,8 +8,19 @@
ermoji_gadget <- function() {
require(shiny)
require(miniUI)
runGadget(ermoji_ui(), ermoji_server, viewer = paneViewer(500), stopOnCancel = FALSE)
}

ermoji_shiny <- function() {
require(shiny)
require(miniUI)
shinyApp(ui = ermoji_ui(), server = ermoji_server)
}

ui <- miniPage(

ermoji_ui <- function() {
miniPage(
title = "ermoji",
gadgetTitleBar("ermoji"),
miniContentPanel(
padding = 10,
@@ -21,84 +32,81 @@ ermoji_gadget <- function() {
actionButton("copy_gliph", "Copy Emoji", class = "btn-primary")
)
)
}

server <- function(input, output, session) {
output$emojis <- DT::renderDataTable({
emojis <- emo::jis
emojis <- emojis[, c('emoji', 'name', "group", "keywords", "aliases")]
emojis$keywords <- purrr::map_chr(emojis$keywords, ~ paste(., collapse = ", "))
emojis$aliases <- purrr::map_chr(emojis$aliases, ~ paste(., collapse = ", "))
DT::datatable(
emojis,
rownames = FALSE,
colnames = c("Emoji", "Name", "Group", "Keywords", "Aliases"),
filter = "top",
selection = "single",
fillContainer = TRUE,
# style = 'bootstrap',
class = 'compact stripe nowrap hover',
options = list(
searchHighlight = TRUE,
search = list(regex = TRUE, caseInsensitive = FALSE),
columnDefs = list(list(
className = "dt-center", targets = 0
)),
pageLength = 10,
lengthMenu = c(4, 5, 10)
)
ermoji_server <- function(input, output, session) {
output$emojis <- DT::renderDataTable({
emojis <- emo::jis
emojis <- emojis[, c('emoji', 'name', "group", "keywords", "aliases")]
emojis$keywords <- purrr::map_chr(emojis$keywords, ~ paste(., collapse = ", "))
emojis$aliases <- purrr::map_chr(emojis$aliases, ~ paste(., collapse = ", "))
DT::datatable(
emojis,
rownames = FALSE,
colnames = c("Emoji", "Name", "Group", "Keywords", "Aliases"),
filter = "top",
selection = "single",
fillContainer = TRUE,
# style = 'bootstrap',
class = 'compact stripe nowrap hover',
options = list(
searchHighlight = TRUE,
search = list(regex = TRUE, caseInsensitive = FALSE),
columnDefs = list(list(
className = "dt-center", targets = 0
)),
pageLength = 10,
lengthMenu = c(4, 5, 10)
)
})

this_emoji <- reactive({
req(input$emojis_rows_selected)
as.list(emo::jis[input$emojis_rows_selected, ])
})
)
})

this_emoji_name <- reactive({
# name <- this_emoji()$name
name <- this_emoji()$aliases[[1]][1]
paste0(":", gsub(" ", "_", name), ":")
})
this_emoji <- reactive({
req(input$emojis_rows_selected)
as.list(emo::jis[input$emojis_rows_selected, ])
})

this_emoji_uni <- reactive({
uni <- paste0("\\U", this_emoji()$runes)
gsub(" ", "\\\\U", uni)
})
this_emoji_name <- reactive({
# name <- this_emoji()$name
name <- this_emoji()$aliases[[1]][1]
paste0(":", gsub(" ", "_", name), ":")
})

this_emoji_uni_trunc <- reactive({
uni <- this_emoji()$runes
uni <- sub(" .+", "...", uni)
paste0("\\U", uni)
})
this_emoji_uni <- reactive({
uni <- paste0("\\U", this_emoji()$runes)
gsub(" ", "\\\\U", uni)
})

observeEvent(input$emojis_rows_selected, {
if (!isTruthy(input$emojis_rows_selected)) {
updateActionButton(session, "copy_name", "Copy :emoji_name:")
updateActionButton(session, "copy_utf", "Copy Unicode")
updateActionButton(session, "copy_gliph", "Copy Emoji")
} else {
updateActionButton(session, "copy_name", paste0("Copy <code>", this_emoji_name(), "</code>"))
updateActionButton(session, "copy_utf", paste("Copy <code>", this_emoji_uni_trunc(), "</code>"))
updateActionButton(session, "copy_gliph", paste("Copy", this_emoji()$emoji))
}
})
observeEvent(input$copy_name, {
clipr::write_clip(this_emoji_name())
})
observeEvent(input$copy_utf, {
clipr::write_clip(this_emoji_uni())
})
observeEvent(input$copy_gliph, {
clipr::write_clip(this_emoji()$emoji)
})
observeEvent(input$done, {
stopApp(invisible())
})
observeEvent(input$cancel, {
stopApp(invisible())
})
}
this_emoji_uni_trunc <- reactive({
uni <- this_emoji()$runes
uni <- sub(" .+", "...", uni)
paste0("\\U", uni)
})

runGadget(ui, server, viewer = paneViewer(500), stopOnCancel = FALSE)
observeEvent(input$emojis_rows_selected, {
if (!isTruthy(input$emojis_rows_selected)) {
updateActionButton(session, "copy_name", "Copy :emoji_name:")
updateActionButton(session, "copy_utf", "Copy Unicode")
updateActionButton(session, "copy_gliph", "Copy Emoji")
} else {
updateActionButton(session, "copy_name", paste0("Copy <code>", this_emoji_name(), "</code>"))
updateActionButton(session, "copy_utf", paste("Copy <code>", this_emoji_uni_trunc(), "</code>"))
updateActionButton(session, "copy_gliph", paste("Copy", this_emoji()$emoji))
}
})
observeEvent(input$copy_name, {
clipr::write_clip(this_emoji_name())
})
observeEvent(input$copy_utf, {
clipr::write_clip(this_emoji_uni())
})
observeEvent(input$copy_gliph, {
clipr::write_clip(this_emoji()$emoji)
})
observeEvent(input$done, {
stopApp(invisible())
})
observeEvent(input$cancel, {
stopApp(invisible())
})
}


Loading…
Annulla
Salva