From 184d2e0fd2ad1fba0ff515c1dd3f70160a0649b9 Mon Sep 17 00:00:00 2001 From: "Marton A. Varga" Date: Wed, 16 Oct 2024 23:25:23 +0200 Subject: [PATCH 1/3] popup --- R/app_server.R | 44 ++++++++++++++++++++++++++++++++++++++++++++ app.R | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/R/app_server.R b/R/app_server.R index d5571ae..8c7a8e8 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -1,5 +1,49 @@ #' @import shiny +#' @import shinyjs app_server <- function(input, output,session) { + observe({ + if (is.null(session$userData$app_open_count)) { + session$userData$app_open_count <- shiny::reactiveVal(0) + } + + app_open_count <- session$userData$app_open_count() + session$userData$app_open_count(app_open_count + 1) + + # if ((session$userData$app_open_count() %% 4) == 0) { + # shiny::showModal( + # shiny::modalDialog( + # title = "Support the development of Tenzing!", + # easyClose = TRUE, + # footer = modalButton("Close"), + # tagList( + # p("Consider donating to support future development!"), + # tags$a(href = "https://opencollective.com/tenzing", "Click here to donate!", target = "_blank") + # ) + # ) + # ) + # } + +if ((session$userData$app_open_count() %% 4) == 0) { + # Show a non-aggressive pop-up notification using shinyjs + shinyjs::runjs(" + const div = document.createElement('div'); + div.innerHTML = 'Support the App!
Consider donating here!'; + div.style.position = 'fixed'; + div.style.bottom = '20px'; + div.style.right = '20px'; + 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 10 seconds + setTimeout(function() { div.remove(); }, 10000); + ") + } + }) + # Read in the contributors_table ## Save the read data as a reactive object read_out <- mod_read_spreadsheet_server("read_spreadsheet") diff --git a/app.R b/app.R index 6075e07..fdb4c5a 100644 --- a/app.R +++ b/app.R @@ -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 From c48379796dd8559a2a4588f7c01177ae13c537da Mon Sep 17 00:00:00 2001 From: "Alex O. Holcombe" Date: Wed, 6 Nov 2024 08:14:27 +1100 Subject: [PATCH 2/3] Update app_ui.R shinyJS, needed for pop-up --- R/app_ui.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/app_ui.R b/R/app_ui.R index 5fd5c9d..60721a5 100644 --- a/R/app_ui.R +++ b/R/app_ui.R @@ -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("