Spaces:
Sleeping
Sleeping
| # MCAT Deployment Script for shinyapps.io | |
| # Run this script to deploy your MCAT application | |
| # ============================================================================== | |
| # STEP 1: Install required packages (run once) | |
| # ============================================================================== | |
| install_if_missing <- function(packages) { | |
| new_packages <- packages[!(packages %in% installed.packages()[, "Package"])] | |
| if (length(new_packages)) { | |
| install.packages(new_packages) | |
| } | |
| } | |
| # Required packages for the app | |
| required_packages <- c( | |
| "shiny", | |
| "mirt", | |
| "mirtCAT", | |
| "dplyr", | |
| "ggplot2", | |
| "rsconnect" | |
| ) | |
| install_if_missing(required_packages) | |
| # ============================================================================== | |
| # STEP 2: Configure shinyapps.io account | |
| # ============================================================================== | |
| # You need to get your token and secret from shinyapps.io: | |
| # 1. Go to https://www.shinyapps.io/ | |
| # 2. Create a free account (or log in) | |
| # 3. Click on your name (top right) -> Tokens | |
| # 4. Click "Show" next to a token, then "Show Secret" | |
| # 5. Copy the values below | |
| # UNCOMMENT AND FILL IN YOUR CREDENTIALS: | |
| # rsconnect::setAccountInfo( | |
| # name = "YOUR_ACCOUNT_NAME", | |
| # token = "YOUR_TOKEN", | |
| # secret = "YOUR_SECRET" | |
| # ) | |
| # ============================================================================== | |
| # STEP 3: Verify files are ready | |
| # ============================================================================== | |
| app_dir <- getwd() # Should be the MCAT directory | |
| # Check required files exist | |
| required_files <- c("app.R", "Fullmodel.rds") | |
| missing_files <- required_files[!file.exists(file.path(app_dir, required_files))] | |
| if (length(missing_files) > 0) { | |
| stop("Missing required files: ", paste(missing_files, collapse = ", "), | |
| "\nMake sure you're in the correct directory and have all files.") | |
| } else { | |
| message("All required files found!") | |
| } | |
| # ============================================================================== | |
| # STEP 4: Deploy to shinyapps.io | |
| # ============================================================================== | |
| # Deploy the app | |
| # Change "mcat-assessment" to your preferred app name | |
| deploy_app <- function(app_name = "mcat-assessment") { | |
| library(rsconnect) | |
| message("Deploying to shinyapps.io...") | |
| message("This may take a few minutes on first deployment.") | |
| rsconnect::deployApp( | |
| appDir = app_dir, | |
| appName = app_name, | |
| appTitle = "MCAT - Mental Health Assessment", | |
| appFiles = c( | |
| "app.R", | |
| "Fullmodel.rds" | |
| # Add "Fulldata.rds" here if needed | |
| ), | |
| forceUpdate = TRUE | |
| ) | |
| message("\nDeployment complete!") | |
| message(sprintf("Your app is available at: https://%s.shinyapps.io/%s", | |
| rsconnect::accounts()$name[1], app_name)) | |
| } | |
| # ============================================================================== | |
| # USAGE: | |
| # ============================================================================== | |
| # | |
| # 1. First, configure your shinyapps.io credentials above (Step 2) | |
| # | |
| # 2. Then run: | |
| # source("deploy.R") | |
| # deploy_app() | |
| # | |
| # 3. Or deploy with a custom name: | |
| # deploy_app("my-mcat-app") | |
| # | |
| # ============================================================================== | |
| message("Deployment script loaded!") | |
| message("Configure your shinyapps.io credentials, then run: deploy_app()") | |