Skip to content

Commit

Permalink
shiny app
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Apr 24, 2024
1 parent 5a48349 commit 60b6df6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
8 changes: 8 additions & 0 deletions inst/shinyApp/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ smallInput <- function(Input) {
tagQ$find("input")$addClass("input-sm form-control-sm")$allTags()
}

isPositiveIntegerOrNA <- function(x) {
if(is.na(x) || (x >= 0 && x %% 1 == 0)){
NULL
} else {
"Must be an integer or empty."
}
}

19 changes: 12 additions & 7 deletions inst/shinyApp/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ shinyServer(function(input, output, session){
sv_regex("^[a-zA-Z0-9\\+]+$", "Only alphanumeric or 'c++'")
)
iv$add_rule("pattern", sv_required())
iv$add_rule("depth", sv_integer())
iv$add_rule("maxCount", sv_integer())
iv$add_rule("depth", isPositiveIntegerOrNA)
iv$add_rule("maxCount", isPositiveIntegerOrNA)
iv$enable()

shinyDirChoose(
Expand Down Expand Up @@ -46,12 +46,17 @@ shinyServer(function(input, output, session){
Tabsets <- reactiveVal(character(0L))
Editors <- reactiveVal(character(0L))

negativeDepth <- reactive({
req(input[["depth"]] %% 1 == 0)
if(input[["depth"]] < 0) TRUE
Depth <- reactive({
if(!is.na(input[["depth"]])) {
input[["depth"]]
}
})

infiniteDepth <- reactive({
if(is.na(input[["depth"]])) TRUE
})

observeEvent(negativeDepth(), {
observeEvent(infiniteDepth(), {
show_toast(
title = "Unlimited depth",
text = "Be sure that the current folder is not too deep",
Expand Down Expand Up @@ -220,7 +225,7 @@ shinyServer(function(input, output, session){
fifWidget <- findInFiles(
ext = isolate(input[["ext"]]),
pattern = isolate(input[["pattern"]]),
depth = isolate(input[["depth"]]),
depth = isolate(Depth()),
maxCount = isolate(maxCount()),
wholeWord = isolate(input[["wholeWord"]]),
ignoreCase = isolate(input[["ignoreCase"]])
Expand Down
8 changes: 4 additions & 4 deletions inst/shinyApp/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ shinyUI(fluidPage(
"pattern", "Pattern:"
),
smallInput(numericInput(
"depth", "Depth; set -1 for unlimited:",
value = 1, min = -1, step = 1
"depth", "Depth; blank for unlimited:",
value = 1, min = 0, step = 1
)),
actionButton(
"run", "Find",
Expand All @@ -52,8 +52,8 @@ shinyUI(fluidPage(
)
),
smallInput(numericInput(
"maxCount", "Maximal number of results; set 0 for unlimited:",
value = 100, min = 0, step = 50
"maxCount", "Maximal number of results; blank for unlimited:",
value = 100, min = 1, step = 50
))
),
mainPanel(
Expand Down

0 comments on commit 60b6df6

Please sign in to comment.