This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
{css2r} is an R package that extracts CSS styles from a website and generates a bslib-compatible Shiny theme. It ships both as a reusable R6 class (css2r) and as a Shiny app (named "Shiny Copy") that wraps it.
The package is built with the {golem} framework, which structures Shiny apps as R packages.
All commands are run from an R console inside the project.
Develop interactively (runs the Shiny app in dev mode):
source("dev/run_dev.R")Run all tests:
devtools::test()Run a single test file:
devtools::test(filter = "css2r")Document and reload the package:
golem::document_and_reload()Check the package (equivalent of R CMD check):
devtools::check()Update DESCRIPTION dependencies from parsed imports:
attachment::att_amend_desc()Rebuild README.md from README.Rmd:
devtools::build_readme()The css2r R6 class is the main logic unit. It performs a sequential pipeline on initialization:
check_internet()— verifies connectivity via{curl}download_html()— fetches the page with{rvest}extract_css_links()— parses<link rel="stylesheet">tagsfilter_css_links()— keeps only links from the same domaindownload_css_files()— fetches CSS content via{httr}extract_colors()— regex-extracts 6-digit hex colors, counts frequencyanalyze_colors()— splits white/black from top-4 brand colorsdetect_google_fonts()— identifies Google Fonts from CSS link paramsgenerate_shiny_code()— assemblesbslib::bs_theme()call and stores it in$shiny_codeand$shiny_theme
Each step can also be called manually by passing on_initialize = FALSE.
R/app_ui.R— UI definition usingbslib::page()with Bootstrap 5; a URL input + task button, anduiOutputplaceholders for resultsR/app_server.R— server logic: callscss2r$new(), applies the extracted theme live viasession$setCurrentTheme(), and sends top colors to JS viasession$sendCustomMessage(type = "apply_gradient", ...)R/run_app.R— exportedrun_app()function (golem entry point)R/app_config.R— golem configuration helpers (app_sys(),get_golem_options())inst/app/www/— static assets:custom.css,handler.js(handles theapply_gradientJS message),favicon.icoapp.R— thin launcher for deployment (pkgload::load_all()+run_app())
Tests live in tests/testthat/. The main test (test-css2r.R) hits the live thinkr.fr website and is wrapped in skip_if_offline(). CI runs R CMD check across macOS, Windows, and Ubuntu via .github/workflows/R-CMD-check.yaml.