|
| 1 | +--- |
| 2 | +title: "20250729:fenA processx_convert & theme" |
| 3 | +draft: false |
| 4 | +tags: |
| 5 | + - Dry |
| 6 | + - Linux |
| 7 | + - ShinyApp |
| 8 | + - Functional-Enrichment-Analysis |
| 9 | +--- |
| 10 | +# Today's task |
| 11 | + |
| 12 | +1. Make fenA fit with our [loc](https://github.com/LabOnoM/ShinyAppsManager) platform |
| 13 | +2. Convert the main loop of fenA ShinyApp into Subprocesses of R session by using [processx](https://github.com/r-lib/processx) |
| 14 | +3. Change the theme of fenA ShinyApp into the uniformed format |
| 15 | +4. If possible, draw software scheme for the main logic in fenA ShinyApp |
| 16 | + |
| 17 | +# 1. Add code blocks for [loc](https://github.com/LabOnoM/ShinyAppsManager) |
| 18 | + |
| 19 | +## Basic functions |
| 20 | +1. Handle crash |
| 21 | +2. Email notification |
| 22 | +3. Communications with [loc](https://github.com/LabOnoM/ShinyAppsManager) based on [jwt](https://en.wikipedia.org/wiki/JSON_Web_Token) |
| 23 | + |
| 24 | +Example codes: |
| 25 | +```R |
| 26 | + # Fetch information if running on BSGOU loc (local allocation controller) system. |
| 27 | + observe({ |
| 28 | + req(values$is_on_shiny_server) |
| 29 | + req(values$server_connected) |
| 30 | + req(is.null(session$userData$email)) |
| 31 | + invalidateLater(10000, session) |
| 32 | + msg <- "Checking email" |
| 33 | + isolate(values$console_log <-c(values$console_log, print_to_console(msg))) |
| 34 | + isolate({values$console_log <- c(values$console_log, msg)}) |
| 35 | + session$userData$email <- get_user_email(session$userData$token) |
| 36 | + isolate(UserEmail <- session$userData$email) |
| 37 | + msg <- paste0("Your email is: ", UserEmail) |
| 38 | + isolate(values$console_log <-c(values$console_log, print_to_console(msg))) |
| 39 | + isolate({values$console_log <- c(values$console_log, msg)}) |
| 40 | + msg <- "Welcome to BSGOU!" |
| 41 | + isolate(values$console_log <-c(values$console_log, print_to_console(msg))) |
| 42 | + isolate({values$console_log <- c(values$console_log, msg)}) |
| 43 | + isolate(values$user_email_checked <- TRUE) |
| 44 | + }) |
| 45 | + output$EmailNotif_ui <- renderUI({ |
| 46 | + req(values$user_email_checked ) |
| 47 | + req(!is.null(session$userData$email)) |
| 48 | + req(values$is_on_shiny_server) |
| 49 | + label <- paste0("Enable Email Notification to: ", session$userData$email) |
| 50 | + checkboxInput("EmailNotif", label = label, value = TRUE) |
| 51 | + }) |
| 52 | + observe({ |
| 53 | + msg <- "The console is working" |
| 54 | + isolate(values$console_log <-c(values$console_log, print_to_console(msg))) |
| 55 | + req(isolate(values$is_on_shiny_server)) |
| 56 | + ## start-3嵌入代码开始,作用:进入/退出HTTP请求记录 |
| 57 | + query <- parseQueryString(session$clientData$url_search) |
| 58 | + session$userData$id <- query$id |
| 59 | + session$userData$appName <- query$appName |
| 60 | + session$userData$token <- query$token |
| 61 | + headers <- httr::add_headers(`Token`=session$userData$token, `Content-Type`="application/json") |
| 62 | + connect_req = list(`appName`=session$userData$appName, `action`="connect", `id`=session$userData$id) |
| 63 | + connect_data <- try( |
| 64 | + url_execute( |
| 65 | + 2, 'http://10.2.26.152/sqx_fast/app/workstation/shiny-connect-action', |
| 66 | + toJSON(connect_req, pretty = FALSE,auto_unbox = TRUE), headers), silent = TRUE |
| 67 | + ) |
| 68 | + values$server_connected<-TRUE |
| 69 | + if (connect_data$code!=0) {session$close()} |
| 70 | + ## end-3嵌入代码开始,作用:进入/退出HTTP请求记录 |
| 71 | + }) |
| 72 | + output$conditional_head <- renderUI({ |
| 73 | + if(isolate(values$is_on_shiny_server)){ |
| 74 | + ## start-1嵌入代码开始,作用:异常跳转到预约系统首页 |
| 75 | + tags$head( |
| 76 | + tags$script(HTML(" |
| 77 | + $(document).on('shiny:disconnected', function(event) { |
| 78 | + window.location.href = 'http://10.2.26.152/'; |
| 79 | + }); |
| 80 | + ")) |
| 81 | + ) |
| 82 | + ## end-1嵌入代码结束,作用:异常跳转到预约系统首页 |
| 83 | + }else{ |
| 84 | + NULL |
| 85 | + } |
| 86 | + }) |
| 87 | + ## Handle crash info ---- |
| 88 | + # Pop up dialog to show error message |
| 89 | + observeEvent(values$error_state, { |
| 90 | + if(!is.null(values$error_state)){ |
| 91 | + SoftwareCrashInfo(error_state = values$error_state, input = input, output = output, main_session=session) |
| 92 | + values$error_state<-NULL |
| 93 | + } |
| 94 | + }) |
| 95 | + # Observe button click to close modal |
| 96 | + observeEvent(input$Crash_modal_ok, { |
| 97 | + shiny::removeModal() |
| 98 | + }) |
| 99 | +``` |
| 100 | + |
| 101 | +# 2. Convert Main loop with [processx](https://github.com/r-lib/processx) |
| 102 | + |
0 commit comments