Skip to content

Commit

Permalink
Merge pull request #29 from CSAFE-ISU/26-fix-warnings
Browse files Browse the repository at this point in the history
26 fix warnings
  • Loading branch information
stephaniereinders authored Oct 30, 2024
2 parents e84ab90 + 8b49765 commit ea49204
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 32 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ LazyData: true
Imports:
bslib,
dplyr,
ggplot2,
handwriter,
handwriterRF,
magick,
magrittr,
rmarkdown,
Expand Down
8 changes: 4 additions & 4 deletions R/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ handwriterApp <- function(...){
# placing the home page inside a module becomes quite complicated.

# Switch to Scenario 1 tab
observeEvent(input$open_button, {
updateNavbarPage(session, "my-navbar", selected = "Scenario 1")
shiny::observeEvent(input$open_button, {
shiny::updateNavbarPage(session, "my-navbar", selected = "Scenario 1")
})

# Switch to Scenario 2 tab
observeEvent(input$closed_button, {
updateNavbarPage(session, "my-navbar", selected = "Scenario 2")
shiny::observeEvent(input$closed_button, {
shiny::updateNavbarPage(session, "my-navbar", selected = "Scenario 2")
})

openServer('open1')
Expand Down
4 changes: 2 additions & 2 deletions R/closed-demo-preview.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ demoPreviewServer <- function(id, global) {

# create a reactive for each model doc
model_reactives <- lapply(model_docs, function(doc) {
reactive({
shiny::reactive({
list(datapath = doc)
})
})

# create a reactive for each questioned doc
questioned_reactives <- lapply(questioned_docs, function(doc) {
reactive({
shiny::reactive({
list(datapath = doc)
})
})
Expand Down
2 changes: 1 addition & 1 deletion R/graphs.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ graphsServer <- function(id, sample, graphs) {
id,
function(input, output, session) {
output$path <- shiny::renderText({
req(sample()$datapath)
shiny::req(sample()$datapath)
basename(sample()$datapath)
})

Expand Down
4 changes: 2 additions & 2 deletions R/home.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ homeServer <- function(id){
shiny::moduleServer(
id,
function(input, output, session){
observeEvent(input$open_button, {
updateNavbarPage(session, "my-navbar", selected = "Open-Set")
shiny::observeEvent(input$open_button, {
shiny::updateNavbarPage(session, "my-navbar", selected = "Open-Set")
})
}
)
Expand Down
40 changes: 20 additions & 20 deletions R/open-master.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ openServer <- function(id){
function(input, output, session){

# ON / OFF BUTTON FOR RESULTS DISPLAY ----
display <- reactiveValues(show = FALSE)
display <- shiny::reactiveValues(show = FALSE)

# graphs
graphs <- shiny::reactiveValues(sample1 = NULL,
Expand All @@ -79,7 +79,7 @@ openServer <- function(id){
sample2 = NULL)

# LOAD ----
sample1 <- reactive({
sample1 <- shiny::reactive({
cat(file=stderr(), "sample1 reactive \n")

# turn off slr display
Expand All @@ -92,7 +92,7 @@ openServer <- function(id){
}) %>%
shiny::bindEvent(input$open_upload1)

sample2 <- reactive({
sample2 <- shiny::reactive({
cat(file=stderr(), "sample2 reactive \n")

# turn off slr display
Expand All @@ -105,15 +105,15 @@ openServer <- function(id){
}) %>%
shiny::bindEvent(input$open_upload2)

template_plot <- reactive({
template_plot <- shiny::reactive({
x <- list()
x$datapath <- system.file(file.path("extdata", "images", "template.png"), package = "handwriterApp")
return(x)
})

# calculate slr
slr_df <- reactive({
req(sample1(), sample2())
slr_df <- shiny::reactive({
shiny::req(sample1(), sample2())

cat(file=stderr(), "slr_df reactive \n")

Expand Down Expand Up @@ -149,7 +149,7 @@ openServer <- function(id){
# RENDER ----
# display handwriting samples
output$samples_display <- shiny::renderUI({
req(sample1(), sample2())
shiny::req(sample1(), sample2())
ns <- session$ns

cat(file=stderr(), "render samples UI \n")
Expand All @@ -164,7 +164,7 @@ openServer <- function(id){

# display hypotheses
output$hypotheses_display <- shiny::renderUI({
req(sample1(), sample2())
shiny::req(sample1(), sample2())
ns <- session$ns

cat(file=stderr(), "render hypotheses UI \n")
Expand All @@ -185,7 +185,7 @@ openServer <- function(id){

# display limitations
output$limitations_display <- shiny::renderUI({
req(sample1(), sample2())
shiny::req(sample1(), sample2())
ns <- session$ns

cat(file=stderr(), "render limiations UI \n")
Expand All @@ -206,7 +206,7 @@ openServer <- function(id){

# display writer profiles
output$profiles_display <- shiny::renderUI({
req(clusters$sample1, clusters$sample2, display$show)
shiny::req(clusters$sample1, clusters$sample2, display$show)
ns <- session$ns

cat(file=stderr(), "render writer profiles UI \n")
Expand Down Expand Up @@ -237,15 +237,15 @@ openServer <- function(id){

# display similarity score
output$score <- shiny::renderText({
req(slr_df(), display$show)
shiny::req(slr_df(), display$show)

cat(file=stderr(), "render score \n")
slr_df()$score
})

# display slr
output$slr <- shiny::renderText({
req(slr_df(), display$show)
shiny::req(slr_df(), display$show)

cat(file=stderr(), "render slr \n")

Expand All @@ -264,26 +264,26 @@ openServer <- function(id){

# display slr interpretation
output$slr_interpretation <- shiny::renderText({
req(slr_df(), display$show)
shiny::req(slr_df(), display$show)
cat(file=stderr(), "render interpretation \n")
handwriterRF::interpret_slr(slr_df())
})

# display slr results
output$slr_display <- shiny::renderUI({
req(sample1(), sample2(), slr_df(), display$show)
shiny::req(sample1(), sample2(), slr_df(), display$show)
ns <- session$ns

cat(file=stderr(), "render slr UI \n")

shiny::tagList(
shiny::h1("COMPARISON RESULTS"),
shiny::HTML("<p>Handwriter measures the similarity between the two writer profiles using a random forest trained
on handwriting samples from the <a href='https://data.csafe.iastate.edu/HandwritingDatabase/'>CSAFE Handwriting Database</a>.
The result is a <i>similarity score</i> between the two writer profiles. Next, handwriter calculates the likelihood of observing the similarity score if the 'same writer' hypothesis is true and the likelihood
on handwriting samples from the <a href='https://data.csafe.iastate.edu/HandwritingDatabase/'>CSAFE Handwriting Database</a>.
The result is a <i>similarity score</i> between the two writer profiles. Next, handwriter calculates the likelihood of observing the similarity score if the 'same writer' hypothesis is true and the likelihood
of observing the similarity score if the 'different writers' hypothesis is true. The <i>score-based likelihood ratio</i> is the ratio of these
two likelihoods. For more information, see <cite><a hrer='https://doi.org/10.1002/sam.11566'>Handwriting identification using random forests
and scorebased likelihood ratios.</a></cite></p>
and score-based likelihood ratios.</a></cite></p>
"
),
shiny::h2("Similarity Score"),
Expand All @@ -302,12 +302,12 @@ openServer <- function(id){
singleImageServer("sample1", sample1)
singleImageServer("sample2", sample2)

graphsServer("sample1_graphs", sample1, reactive(graphs$sample1))
graphsServer("sample2_graphs", sample2, reactive(graphs$sample2))
graphsServer("sample1_graphs", sample1, shiny::reactive(graphs$sample1))
graphsServer("sample2_graphs", sample2, shiny::reactive(graphs$sample2))

singleImageServer("template1", template_plot, title = "Clusters")

writerProfileServer("writer_profiles", sample1, sample2, reactive(clusters))
writerProfileServer("writer_profiles", sample1, sample2, shiny::reactive(clusters))
}
)
}
34 changes: 34 additions & 0 deletions R/plots.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
# The 'handwriterApp' 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/>.

# Internal Functions ------------------------------------------------------

#' Plot Writer Profiles
#'
#' Create a line plot of cluster fill rates for one or more documents, where the
#' cluster fill rates serve as writer profiles. Each cluster fill rates for each
#' document are plotted as different colored lines.
#'
#' @param rates A data frame of cluster fill rates created with
#' \code{\link[handwriterRF]{get_cluster_fill_rates}}
#'
#' @return A line plot
#'
#' @noRd
#'
plot_writer_profiles <- function(rates) {
# prevent note: "no visible binding for global variable"
docname <- cluster <- rate <- NULL

rates <- rates %>%
tidyr::pivot_longer(cols = -tidyr::any_of(c("docname", "total_graphs")), names_to = "cluster", values_to = "rate") %>%
Expand Down
4 changes: 2 additions & 2 deletions R/single-image.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ singleImageServer <- function(id, sample, title = NULL) {
if (!is.null(title)){
title
} else {
req(sample()$datapath)
shiny::req(sample()$datapath)
basename(sample()$datapath)
}
})

output$image <- shiny::renderImage({
req(sample()$datapath)
shiny::req(sample()$datapath)

image <- magick::image_read(sample()$datapath)
tmp <- image %>%
Expand Down
2 changes: 1 addition & 1 deletion R/writer-profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ writerProfileServer <- function(id, sample1, sample2, clusters) {
id,
function(input, output, session) {
output$path <- shiny::renderText({
req(sample1()$datapath, sample2()$datapath)
shiny::req(sample1()$datapath, sample2()$datapath)
paste(basename(sample1()$datapath), "and", basename(sample2()$datapath))
})

Expand Down

0 comments on commit ea49204

Please sign in to comment.