Skip to content

Commit

Permalink
Merge pull request #92 from marton-balazs-kovacs/popup
Browse files Browse the repository at this point in the history
Popup
  • Loading branch information
alexholcombe authored Jan 23, 2025
2 parents c958198 + 6d9149a commit 8ae7b0a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
40 changes: 40 additions & 0 deletions R/app_server.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
#' @import shiny
#' @import shinyjs
app_server <- function(input, output,session) {
show_popup = FALSE
observe({
if (is.null(session$userData$app_open_count)) {
session$userData$app_open_count <- shiny::reactiveVal(0)

#Calculate whether should create the pop-up, by using the date/time as a random number proxy
# Get the current time
current_time <- Sys.time()
# Format the time as a continuous string
formatted_time <- format(current_time, "%Y%m%d%H%M%S")
# Convert the string to a numeric value
numeric_time <- as.numeric(formatted_time)
if ((numeric_time %% 3) == 0) { #modulus two seems to make it show up less than 50% of time?
show_popup = TRUE
}

}

if (show_popup) {
# Show a non-aggressive pop-up notification using shinyjs
shinyjs::runjs("
const div = document.createElement('div');
div.innerHTML = 'Please support tenzing &#x1F60A; <br>Donate <a href=\"https://opencollective.com/tenzing\" target=\"_blank\">here</a>!';
div.style.position = 'fixed';
div.style.top = '75%';
div.style.left = '16%';
div.style.padding = '10px';
div.style.background = 'lightblue';
div.style.border = '1px solid gray';
div.style.borderRadius = '5px';
div.style.zIndex = 9999;
document.body.appendChild(div);
// Remove the notification after 60 seconds
setTimeout(function() { div.remove(); }, 60000);
")
}
})

# Read in the contributors_table
## Save the read data as a reactive object
read_out <- mod_read_spreadsheet_server("read_spreadsheet")
Expand Down
1 change: 1 addition & 0 deletions R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ golem_add_external_resources <- function(){
tags$script(src = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.8.4/components/prism-yaml.min.js"),
tags$link(rel = "stylesheet", type = "text/css",
href = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.8.4/themes/prism.min.css"),
shinyjs::useShinyjs(), #To create pop-up, in app_server.R
# Matomo analytics
# includeHTML(app_sys("app/www/usage_tracker.html"))
HTML("<script>
Expand Down
2 changes: 1 addition & 1 deletion app.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Launch the ShinyApp (Do not remove this comment)
11# Launch the ShinyApp (Do not remove this comment)
# To deploy, run: rsconnect::deployApp()
# Or use the blue button on top of this file

Expand Down

0 comments on commit 8ae7b0a

Please # to comment.