/
dyn_extraction_app.R
78 lines (69 loc) · 2.32 KB
/
dyn_extraction_app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 12341.DYN HA types extraction
# 20220820(10.34)
# author: esteeschwarz
# app deployed at:https://vision2020.shinyapps.io/hux2021/
##########################################################
# stages:
# 20220820 working, deployed.
# Load packages ----------------------------------------------------------------
library(shiny)
library(readtext)
#library(markdown)
#library(htmltools)
library(pdftools)
# loaddata
# UI ---------------------------------------------------------------------------
ui <- pageWithSidebar(
# Title ----
headerPanel("Dynamiken postdeutscher Gegenwartslyrik. collaborative essai."),
# Sidebar ----
sidebarPanel(
"please provide a book for further analysis",
fileInput("file1","upload .pdf or .txt file"),
downloadButton("downloadData","download")
),
# Main panel ----
mainPanel(
verbatimTextOutput("contents"),
verbatimTextOutput("thankyou"))
)
# Server -----------------------------------------------------------------------
server <- function(input, output) {
#### outputs:
output$contents <-renderPrint({
file<-input$file1
ext<-tools::file_ext(file$datapath)
req(file)
# validate(need(ext=="pdf"|ext=="txt","please upload a pdf file"))
ifelse (ext=="pdf",extracted<-1,extracted<-2)
#cat(extracted)
textpdf<-"sampletext"
texttxt<-"sampletext"
if (extracted==1){textpdf<-pdf_text(file$datapath)}
if (extracted==2){texttxt<-readtext(file$datapath)$text}
d1<-textpdf
d2<-stri_extract_all_words(d)
d3<-unique(d2[[2]])
e1<-texttxt
e2<-stri_extract_all_words(e1)
e3<-unique(e2[[1]])
ifelse(extracted==1,extract_types<-d3,extract_types<-e3)
print(extract_types)
# extract_types<-unique(stri_extract_all_words(extracted))
# print(extract_types)
output$downloadData<-downloadHandler(
filename="types_extracted.txt",
content=function(file){write_lines(extract_types,file)}
)
output$thankyou<-renderPrint({
cat("Thank you for unterstützung!")
})
# file.create("types_extracted.txt")
})
# output$downloadData<-downloadHandler(
# filename="types_extracted.txt",
# content=function(file){write_lines(extracted,file)}
# )
}
# Create the Shiny app object --------------------------------------------------
shinyApp(ui = ui, server = server)