-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_known.R
70 lines (62 loc) · 2.76 KB
/
demo_known.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
# The handwriterAppDemo R package performs writership analysis of handwritten
# documents. Copyright (C) 2024 Iowa State University of Science and Technology
# on behalf of its Center for Statistics and Applications in Forensic Evidence
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <https://www.gnu.org/licenses/>.
demoKnownSidebarUI <- function(id) {
ns <- shiny::NS(id)
shiny::tagList(
shiny::fluidRow(shiny::column(width=12, shiny::actionButton(ns("demo_known_estimate"), "Estimate Writer Profiles"))),
shiny::br()
)
}
demoKnownBodyUI <- function(id){
ns <- shiny::NS(id)
shiny::tagList(
currentImageUI(ns("demo_known"))
)
}
demoKnownServer <- function(id, global) {
shiny::moduleServer(
id,
function(input, output, session) {
shiny::observeEvent(input$demo_known_estimate, {
# setup tempdir()
temp_dir <- tempdir()
global$main_dir <- file.path(temp_dir, "demo")
create_dir(global$main_dir)
setup_main_dir(global$main_dir)
# known writing samples in tests folder
known_paths <- list.files(file.path("data", "model_docs"), full.names = TRUE)
known_names <- basename(known_paths)
# copy known docs to temp directory > data > model_docs
copy_docs_to_project(main_dir = global$main_dir,
paths = known_paths,
subfolder = "model_docs")
# list known filepaths
global$known_paths <- list_docs(global$main_dir, type = "model", filepaths = TRUE)
global$known_names <- list_names_in_named_vector(global$known_paths)
# fit model
global$model <- handwriter::fit_model(main_dir = global$main_dir,
model_docs = file.path(global$main_dir, "data", "model_docs"),
num_iters = 4000,
num_chains = 1,
num_cores = 1,
writer_indices = c(2, 5),
doc_indices = c(7, 18))
})
currentImageServer("demo_known", global, "model")
}
)
}