Skip to content

Commit 2cffff3

Browse files
committed
add static export functionality with WebDriver
Add static export functionality using WebDriver to control a host browser. - allow user to reuse the exporter object but also keep the old style Kaleido API - allow user to set browser capabilities via setter - allow user to configure html2pdf timeout - use data uri for CDN case and file for offline case when generating the html for static image export - there are size restrictions when using data-uri , webdriver cannot load large data-uri files, so for offline mode, default to using html returned by to_file - use build.rs to download webdriver chromedriver/geckodriver - contains documentation and add example for plotly_static - include an example on how to use static export for json data - refactored usage of imageformat between packages: plotly, plotly_kaleido, plotly_static - the new static export is included in the plotly crate as default and kaleido is marked as deprecated using deprecation warnings - added custom CI setup for Windows as Windows GitHub Action with Chrome setup is unique - expand ci with Firefox + Ubuntu for plotly_static - add ci step for publishing plotly_static Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
1 parent c19e727 commit 2cffff3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+8655
-1002
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
# Script to build examples needed for book artifacts
4+
# This script is used by both the CI build_book job and the book.yml workflow
5+
6+
# Note: static_export example requires Chrome setup for WebDriver functionality
7+
# The CI jobs set up Chrome, while when running locally, you may need to setup
8+
# your browser and webdriver manually to ensure this example works properly.
9+
10+
set -e # Exit on any error
11+
12+
# Function to display usage
13+
usage() {
14+
echo "Usage: $0 <examples_directory>"
15+
echo " examples_directory: Path to the examples directory (e.g., examples or \$GITHUB_WORKSPACE/examples)"
16+
echo ""
17+
echo "This script builds all examples needed for the book documentation."
18+
exit 1
19+
}
20+
21+
# Check if examples directory is provided
22+
if [ $# -ne 1 ]; then
23+
usage
24+
fi
25+
26+
EXAMPLES_DIR="$1"
27+
28+
# Validate that the examples directory exists
29+
if [ ! -d "$EXAMPLES_DIR" ]; then
30+
echo "Error: Examples directory '$EXAMPLES_DIR' does not exist"
31+
exit 1
32+
fi
33+
34+
echo "Building examples for book artifacts from: $EXAMPLES_DIR"
35+
36+
# List of examples needed for the book, sorted alphabetically
37+
# These examples generate HTML files that are included in the book documentation
38+
BOOK_EXAMPLES=(
39+
"3d_charts"
40+
"basic_charts"
41+
"custom_controls"
42+
"financial_charts"
43+
"scientific_charts"
44+
"shapes"
45+
"static_export"
46+
"statistical_charts"
47+
"subplots"
48+
"themes"
49+
)
50+
51+
# Build each example
52+
for example in "${BOOK_EXAMPLES[@]}"; do
53+
example_path="$EXAMPLES_DIR/$example"
54+
55+
if [ ! -d "$example_path" ]; then
56+
echo "Warning: Example directory '$example_path' does not exist, skipping..."
57+
continue
58+
fi
59+
60+
echo "Building $example example..."
61+
cd "$example_path"
62+
63+
# Check if Cargo.toml exists
64+
if [ ! -f "Cargo.toml" ]; then
65+
echo "Warning: No Cargo.toml found in $example_path, skipping..."
66+
cd - > /dev/null
67+
continue
68+
fi
69+
70+
# Run the example
71+
if cargo run; then
72+
echo "✓ Successfully built $example"
73+
else
74+
echo "✗ Failed to build $example"
75+
exit 1
76+
fi
77+
78+
# Return to the original directory
79+
cd - > /dev/null
80+
done
81+
82+
echo "All examples built successfully!"
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Windows environment setup for plotly static export tests
2+
# This script sets up Chrome, chromedriver, and environment variables for Windows CI
3+
4+
param(
5+
[string]$ChromeVersion,
6+
[string]$ChromePath,
7+
[string]$ChromeDriverPath
8+
)
9+
10+
Write-Host "=== Setting up Windows environment for static export ==="
11+
12+
# Find chromedriver path
13+
$chromedriverPath = $ChromeDriverPath
14+
if (-not (Test-Path $chromedriverPath)) {
15+
Write-Host "Action output chromedriver path not found, searching for alternatives..."
16+
17+
$commonPaths = @(
18+
"C:\Program Files\Google\Chrome\Application\chromedriver.exe",
19+
"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe",
20+
"$env:USERPROFILE\AppData\Local\Google\Chrome\Application\chromedriver.exe",
21+
"$env:PROGRAMFILES\Google\Chrome\Application\chromedriver.exe",
22+
"$env:PROGRAMFILES(X86)\Google\Chrome\Application\chromedriver.exe"
23+
)
24+
25+
foreach ($path in $commonPaths) {
26+
if (Test-Path $path) {
27+
Write-Host "Using chromedriver from: $path"
28+
$chromedriverPath = $path
29+
break
30+
}
31+
}
32+
}
33+
34+
# Find Chrome path
35+
$chromePath = $ChromePath
36+
if (-not (Test-Path $chromePath)) {
37+
# Try the tool cache path first
38+
$toolCachePath = "C:\hostedtoolcache\windows\setup-chrome\chromium\$ChromeVersion\x64\chrome.exe"
39+
if (Test-Path $toolCachePath) {
40+
$chromePath = $toolCachePath
41+
Write-Host "Using Chrome from setup-chrome installation: $chromePath"
42+
} else {
43+
# Fallback: search for Chrome in the tool cache
44+
$toolCacheDir = "C:\hostedtoolcache\windows\setup-chrome\chromium"
45+
if (Test-Path $toolCacheDir) {
46+
$chromeExe = Get-ChildItem -Path $toolCacheDir -Recurse -Name "chrome.exe" | Select-Object -First 1
47+
if ($chromeExe) {
48+
$chromePath = Join-Path $toolCacheDir $chromeExe
49+
Write-Host "Using Chrome from tool cache search: $chromePath"
50+
} else {
51+
$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
52+
Write-Host "Using system Chrome: $chromePath"
53+
}
54+
} else {
55+
$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
56+
Write-Host "Using system Chrome: $chromePath"
57+
}
58+
}
59+
}
60+
61+
# Set environment variables
62+
$env:WEBDRIVER_PATH = $chromedriverPath
63+
$env:BROWSER_PATH = $chromePath
64+
$env:RUST_LOG = "debug"
65+
$env:RUST_BACKTRACE = "1"
66+
$env:ANGLE_DEFAULT_PLATFORM = "swiftshader"
67+
68+
Write-Host "Environment variables set:"
69+
Write-Host "WEBDRIVER_PATH: $env:WEBDRIVER_PATH"
70+
Write-Host "BROWSER_PATH: $env:BROWSER_PATH"
71+
Write-Host "RUST_LOG: $env:RUST_LOG"
72+
Write-Host "RUST_BACKTRACE: $env:RUST_BACKTRACE"
73+
74+
# Verify paths exist
75+
if (-not (Test-Path $env:WEBDRIVER_PATH)) {
76+
Write-Error "Chromedriver executable not found at: $env:WEBDRIVER_PATH"
77+
Write-Host "Available chromedriver locations:"
78+
Get-ChildItem -Path "C:\Program Files\Google\Chrome\Application\" -Name "chromedriver*" -ErrorAction SilentlyContinue
79+
Get-ChildItem -Path "C:\Program Files (x86)\Google\Chrome\Application\" -Name "chromedriver*" -ErrorAction SilentlyContinue
80+
exit 1
81+
}
82+
83+
if (-not (Test-Path $env:BROWSER_PATH)) {
84+
Write-Error "Chrome not found at: $env:BROWSER_PATH"
85+
exit 1
86+
}
87+
88+
# Test Chrome version
89+
try {
90+
$chromeVersion = & "$env:BROWSER_PATH" --version 2>&1
91+
Write-Host "Chrome version: $chromeVersion"
92+
} catch {
93+
Write-Host "Failed to get Chrome version: $_"
94+
}
95+
96+
# Test chromedriver version
97+
try {
98+
$chromedriverVersion = & "$env:WEBDRIVER_PATH" --version 2>&1
99+
Write-Host "Chromedriver version: $chromedriverVersion"
100+
} catch {
101+
Write-Host "Failed to get chromedriver version: $_"
102+
}
103+
104+
Write-Host "=== Windows environment setup completed ==="

.github/workflows/book.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18+
- name: Setup Chrome (for static_export)
19+
uses: browser-actions/setup-chrome@v1
20+
with:
21+
chrome-version: 'latest'
22+
install-chromedriver: true
1823
- run: cargo install mdbook --no-default-features --features search --vers "^0.4" --locked --quiet
1924
- name: Build examples
20-
run: |
21-
cd ${{ github.workspace }}/examples/basic_charts && cargo run
22-
cd ${{ github.workspace }}/examples/statistical_charts && cargo run
23-
cd ${{ github.workspace }}/examples/scientific_charts && cargo run
24-
cd ${{ github.workspace }}/examples/financial_charts && cargo run
25-
cd ${{ github.workspace }}/examples/3d_charts && cargo run
26-
cd ${{ github.workspace }}/examples/subplots && cargo run
27-
cd ${{ github.workspace }}/examples/shapes && cargo run
25+
run: .github/scripts/build-book-examples.sh ${{ github.workspace }}/examples
2826
- run: mdbook build docs/book
2927
- name: Checkout gh-pages branch
3028
run: |

0 commit comments

Comments
 (0)