Skip to content

Commit

Permalink
add module for doi input #3
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Dec 8, 2020
1 parent 0033608 commit 3dad737
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 13 deletions.
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
URL: https://subugoe.github.io/biblids, https://github.com/subugoe/biblids
BugReports: https://github.com/subugoe/biblids/issues
Imports:
rlang (>= 0.4.9),
checkmate (>= 2.0.0)
Suggests:
testthat,
covr,
subugoetheme
subugoetheme,
shiny
Remotes:
subugoe/[email protected]
Imports:
rlang (>= 0.4.9),
checkmate (>= 2.0.0)
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(doiEntryApp)
export(doiEntryServer)
export(doiEntryUI)
export(is_doi)
73 changes: 65 additions & 8 deletions R/doi.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#' Validate a DOI
#'
#'
#' Validates a [Digital Object Identifier (DOI)](http://doi.org)
#'
#'
#' To resolve DOIs to the associated metadata, you can use the [rcrossref](https://www.crossref.org/blog/dois-and-matching-regular-expressions/) R package.
#'
#'
#' @param x a character string giving a DOI
#'
#' @param type
#'
#' @param type
#' a character string giving the type of validation to run.
#' Implemented as regular expressions (see source code).
#' Must be one these syntax specifications:
#' - from [crossref](https://www.crossref.org/blog/dois-and-matching-regular-expressions/)
#' - `"cr-modern"` currently used crossref DOIs.
#' - `"cr-jws"` for DOIs created by John Wiley & Sons
#' - `"regexpal"` from [regexpal](https://www.regexpal.com/96948) (undocumented, not recommended)
#'
#'
#' @examples
#' is_doi("10.5281/zenodo.3892950") # TRUE
#' is_doi("http://doi.org/10.5281/zenodo.3892951") # TRUE
#' is_doi("lorem ipsum") # FALSE
#'
#' @family doi
#'
#'
#' @export
is_doi <- function(x, type = c("cr-modern", "cr-jws", "regexpal")) {
checkmate::assert_string(x)
Expand All @@ -37,3 +36,61 @@ is_doi <- function(x, type = c("cr-modern", "cr-jws", "regexpal")) {

grepl(pattern = pattern, x = x, ignore.case = TRUE)
}


# shiny modules ====

#' Shiny Module for DOI input
#'
#' Accept, validate and return DOIs in a shiny app.
#' @inheritParams shiny::NS
#' @family doi
#' @name doiEntry
NULL

#' @describeIn doiEntry Test app
#' @export
doiEntryApp <- function() {
requireNamespace2("shiny")
ui <- shiny::fluidPage(doiEntryUI(id = "test"))
server <- function(input, output, session) {
doiEntryServer(id = "test")
}
shiny::shinyApp(ui, server)
}

#' @describeIn doiEntry Module UI
#' @export
doiEntryUI <- function(id) {
requireNamespace2("shiny")
ns <- shiny::NS(id)
shiny::tagList(
shiny::textAreaInput(
inputId = ns("entered"),
label = "DOIs",
placeholder = "10.5281/zenodo.3892950"
),
shiny::actionButton(inputId = ns("submit"), label = "Submit DOIs"),
shiny::verbatimTextOutput(
outputId = ns("found"),
placeholder = TRUE
)
)
}

#' @describeIn doiEntry Module server
#' @export
doiEntryServer <- function(id) {
requireNamespace2("shiny")
shiny::moduleServer(
id,
module = function(input, output, session) {
dois <- shiny::eventReactive(input$submit, {
input$entered
})
output$found <- shiny::renderText({
dois()
})
}
)
}
35 changes: 35 additions & 0 deletions man/doiEntry.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/is_doi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ authors:
href: https://www.maxheld.de
Göttingen State and University Library:
href: https://www.sub.uni-goettingen.de/
reference:
- title: Large Sets of PIDs
desc: Open-ended sets of persistent identifiers
- subtitle: DOIs
desc: Digital Object Identifiers
- contents:
- has_concept("doi")
template:
package: subugoetheme

0 comments on commit 3dad737

Please sign in to comment.