Annotate text with your tags / Annotate areas of interests in images with your own labels
Shift
and click on the image to select
areaslibrary(shiny)
library(recogito)
<- "https://upload.wikimedia.org/wikipedia/commons/a/a0/Pamphlet_dutch_tulipomania_1637.jpg"
url <- "https://iiif.ghentcdh.ugent.be/iiif/images/getuigenissen:brugse_vrije:RABrugge_I15_16999_V02:RABrugge_I15_16999_V02_01/full/full/0/default.jpg"
url <- fluidPage(openseadragonOutput(outputId = "anno", height = "700px"),
ui $h3("Results"),
tagsverbatimTextOutput(outputId = "annotation_result"))
<- function(input, output) {
server <- reactiveValues(url = url)
current_image $anno <- renderOpenSeaDragon({
outputannotorious(inputId = "results", tags = c("Vraag", "Antwoord"), src = current_image$url, type = "openseadragon")
})$annotation_result <- renderPrint({
outputread_annotorious(input$results)
})
}shinyApp(ui, server)
library(shiny)
library(recogito)
library(magick)
library(opencv)
library(sf)
<- "https://upload.wikimedia.org/wikipedia/commons/a/a0/Pamphlet_dutch_tulipomania_1637.jpg"
url <- fluidPage(fluidRow(
ui column(width = 7, annotoriousOutput(outputId = "anno", height = "600px")),
column(width = 5, plotOutput(outputId = "annotation_areas", height = "600px"))),
$h3("Results"),
tagsverbatimTextOutput(outputId = "annotation_result"))
<- function(input, output) {
server <- reactiveValues(img = ocv_read(url), url = url)
current_image $anno <- renderAnnotorious({
outputannotorious(inputId = "results", tags = c("IMAGE", "TEXT"), src = current_image$url, type = "annotorious")
})$annotation_result <- renderPrint({
outputread_annotorious(input$results)
})$annotation_areas <- renderPlot({
output<- read_annotorious(input$results)
x if(nrow(x) > 0){
## Extract the selected polygons and put them below each other so show the selections in annotation_areas
<- ocv_read_annotorious(data = x, image = current_image$img)
areas <- lapply(areas, FUN = function(x) image_read(ocv_bitmap(x)))
overview <- lapply(overview, image_border)
overview <- image_append(do.call(c, overview), stack = TRUE)
overview image_ggplot(overview)
}
})
}shinyApp(ui, server)
Simple example in RStudio
library(recogito)
<- "Josh went to the bakery in Brussels.\nWhat an adventure!"
txt <- recogito(text = txt)
x x
Example with Shiny
With the following code
library(shiny)
library(recogito)
<- "Tell me, O muse, of that ingenious hero who travelled far and wide after he had sacked
txt the famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs
he was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely
home; but do what he might he could not save his men, for they perished through their own sheer folly in eating
the cattle of the Sun-god Hyperion; so the god prevented them from ever reaching home. Tell me, too, about all
these things, O daughter of Jove, from whatsoever source you may know them.\n
So now all who escaped death in battle or by shipwreck had got safely home except Ulysses,
and he, though he was longing to return to his wife and country, was detained by the goddess Calypso, who
had got him into a large cave and wanted to marry him. But as years went by, there came a time when the gods
settled that he should go back to Ithaca; even then, however, when he was among his own people, his troubles
were not yet over; nevertheless all the gods had now begun to pity him except Neptune, who still persecuted
him without ceasing and would not let him get home."
<- "
tagstyles .tag-PERSON { color:red; }
.tag-LOCATION { background-color:green; }
.tag-TIME { font-weight: bold; }
"
<- fluidPage(tags$head(tags$style(HTML(tagstyles))),
ui $br(),
tagsrecogitoOutput(outputId = "annotation_text"),
$h3("Results"),
tagsverbatimTextOutput(outputId = "annotation_result"))
<- function(input, output) {
server $annotation_text <- renderRecogito({
outputrecogito(inputId = "annotations", text = txt, tags = c("LOCATION", "TIME", "PERSON"))
})$annotation_result <- renderPrint({
outputread_recogito(input$annotations)
})
}shinyApp(ui, server)
install.packages("recogito")
remotes::install_github("DIGI-VUB/recogito")
Look to documentation of the functions
help(package = "recogito")
By DIGI: Brussels Platform for Digital Humanities: https://digi.research.vub.be