Skip to content

Commit 9b6b581

Browse files
staredclaude
andcommitted
Add CSV auto-loading for examples with static files
- Add optional csvUrl field to examples for automatic CSV loading - Include sample CSV datasets in public folder: - metal_bands_happiness.csv: Metal bands per capita vs happiness score - startup_funding.csv: Startup funding by sector - global_temperature.csv: Global temperature and CO2 trends - Update examples to use explicit read.csv() commands in code - Make CSV upload only write files to /tmp without auto-loading - Enhance handleExampleSelect to load CSV files when example specifies csvUrl This improves transparency by showing users exactly what code is being executed, while still providing convenient sample datasets. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 9a09586 commit 9b6b581

File tree

9 files changed

+408
-78
lines changed

9 files changed

+408
-78
lines changed

public/global_temperature.csv

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
year,temperature_celsius,co2_ppm,country,continent
2+
2020,14.85,414.24,Global,Global
3+
2019,14.75,411.44,Global,Global
4+
2018,14.69,408.52,Global,Global
5+
2017,14.76,405.55,Global,Global
6+
2016,14.83,404.24,Global,Global
7+
2015,14.72,400.83,Global,Global
8+
2014,14.57,398.65,Global,Global
9+
2013,14.52,396.52,Global,Global
10+
2012,14.48,393.85,Global,Global
11+
2011,14.43,391.65,Global,Global
12+
2010,14.56,389.90,Global,Global
13+
2009,14.49,387.43,Global,Global
14+
2008,14.31,385.60,Global,Global
15+
2007,14.49,383.79,Global,Global
16+
2006,14.42,381.90,Global,Global
17+
2005,14.53,379.80,Global,Global
18+
2004,14.36,377.49,Global,Global
19+
2003,14.44,375.78,Global,Global
20+
2002,14.45,373.28,Global,Global
21+
2001,14.38,371.14,Global,Global
22+
2000,14.26,369.55,Global,Global
23+
1999,14.24,368.38,Global,Global
24+
1998,14.43,366.70,Global,Global
25+
1997,14.31,363.73,Global,Global
26+
1996,14.14,362.61,Global,Global
27+
1995,14.28,360.82,Global,Global
28+
1994,14.18,358.83,Global,Global
29+
1993,14.06,357.10,Global,Global
30+
1992,14.08,356.45,Global,Global
31+
1991,14.26,355.70,Global,Global
32+
1990,14.29,354.39,Global,Global

public/metal_bands_happiness.csv

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Country or region,Overall rank,Metal bands per capita,Score,GDP per capita,Social support,Healthy life expectancy,Freedom to make life choices,Generosity,Perceptions of corruption
2+
Finland,1,630,7.809,1.285,1.5,0.961,0.662,0.16,0.478
3+
Sweden,7,428,7.353,1.322,1.433,0.986,0.65,0.273,0.442
4+
Iceland,4,341,7.504,1.327,1.548,1.001,0.662,0.362,0.145
5+
Norway,5,299,7.488,1.424,1.495,1.008,0.67,0.288,0.434
6+
Greece,77,162,5.515,1.128,1.169,0.979,0.174,0,0.049
7+
Denmark,2,154,7.646,1.327,1.503,0.979,0.665,0.243,0.495
8+
Luxembourg,10,144,7.238,1.537,1.388,0.986,0.61,0.196,0.367
9+
Estonia,51,138,6.022,1.192,1.453,0.843,0.577,0.125,0.202
10+
Malta,22,137,6.773,1.253,1.443,0.972,0.633,0.341,0.179
11+
Netherlands,6,127,7.449,1.339,1.464,0.976,0.614,0.336,0.369
12+
Austria,9,123,7.294,1.317,1.437,1.001,0.603,0.256,0.281
13+
Germany,17,122,7.076,1.314,1.369,0.972,0.564,0.252,0.309
14+
Czech Republic,19,120,6.911,1.212,1.405,0.895,0.506,0.046,0.05
15+
Slovenia,33,120,6.363,1.209,1.465,0.933,0.647,0.146,0.077
16+
Switzerland,3,112,7.56,1.391,1.472,1.041,0.629,0.269,0.408
17+
Portugal,59,112,5.911,1.169,1.34,0.979,0.59,0.053,0.028
18+
Hungary,53,105,6,1.164,1.423,0.807,0.386,0.07,0.028
19+
Belgium,20,101,6.864,1.296,1.399,0.965,0.5,0.147,0.209
20+
Italy,30,97,6.387,1.236,1.347,1.023,0.321,0.17,0.04
21+
Slovakia,37,93,6.281,1.195,1.424,0.853,0.424,0.117,0.011
22+
Croatia,79,90,5.505,1.109,1.311,0.901,0.381,0.114,0.012
23+
Poland,43,80,6.186,1.169,1.31,0.868,0.558,0.063,0.161
24+
Ireland,16,78,7.094,1.447,1.471,0.976,0.588,0.295,0.373
25+
France,23,69,6.664,1.268,1.459,1.03,0.514,0.113,0.227
26+
United Kingdom,13,68,7.165,1.273,1.458,0.976,0.525,0.373,0.323
27+
Spain,28,65,6.401,1.231,1.421,1.051,0.426,0.165,0.11
28+
Lithuania,41,54,6.215,1.194,1.433,0.795,0.42,0.054,0.081
29+
Cyprus,45,52,6.159,1.213,1.149,1.026,0.459,0.228,0.051
30+
Serbia,64,51,5.778,0.988,1.327,0.828,0.395,0.15,0.059
31+
Latvia,57,48,5.95,1.141,1.414,0.778,0.329,0.075,0.09
32+
Bulgaria,96,47,5.102,1.047,1.461,0.778,0.418,0.104,0
33+
North Macedonia,90,44,5.16,0.935,1.183,0.803,0.41,0.186,0.025
34+
Belarus,75,34,5.54,1.019,1.387,0.753,0.291,0.09,0.194
35+
Bosnia and Herzegovina,69,31,5.674,0.918,1.204,0.814,0.305,0.264,0.001
36+
Russia,73,22,5.546,1.127,1.379,0.68,0.399,0.099,0.046
37+
Romania,47,18,6.124,1.12,1.194,0.792,0.535,0.068,0.001
38+
Ukraine,123,17,4.561,0.78,1.321,0.699,0.319,0.179,0.01
39+
Montenegro,72,14,5.546,1.01,1.266,0.839,0.303,0.149,0.098
40+
Turkey,93,6,5.132,1.127,1.197,0.781,0.254,0.086,0.121
41+
Albania,105,4,4.883,0.907,0.83,0.846,0.462,0.171,0.025

public/startup_funding.csv

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
company,sector,country,funding_amount_usd,employees,founded_year,valuation_usd
2+
Stripe,Fintech,USA,95000000,8000,2010,50000000000
3+
SpaceX,Aerospace,USA,85000000,12000,2002,137000000000
4+
Uber,Transportation,USA,82000000,29300,2009,72000000000
5+
Airbnb,Travel,USA,75000000,6132,2008,75000000000
6+
Palantir,Software,USA,70000000,3500,2003,41600000000
7+
ByteDance,Social Media,China,65000000,150000,2012,180000000000
8+
Robinhood,Fintech,USA,55000000,3400,2013,11700000000
9+
Canva,Design,Australia,50000000,4000,2013,40000000000
10+
Klarna,Fintech,Sweden,46000000,7000,2005,31000000000
11+
Revolut,Fintech,UK,42000000,8000,2015,33000000000
12+
Nubank,Fintech,Brazil,40000000,5700,2013,30000000000
13+
Grab,Transportation,Singapore,38000000,9500,2012,40000000000
14+
Checkout.com,Fintech,UK,35000000,2500,2012,40000000000
15+
Plaid,Fintech,USA,32000000,1200,2013,13400000000
16+
Razorpay,Fintech,India,30000000,3500,2014,7500000000
17+
Gojek,Transportation,Indonesia,28000000,5000,2010,10500000000
18+
Figma,Design,USA,25000000,800,2012,20000000000
19+
Notion,Productivity,USA,23000000,500,2016,10000000000
20+
Discord,Communication,USA,22000000,600,2015,15000000000
21+
Miro,Collaboration,Netherlands,20000000,1800,2011,17500000000

src/App.vue

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ const hasChanges = computed(() => code.value !== lastExecutedCode.value)
3030
// GitHub stars
3131
const githubStars = ref<number | null>(null)
3232
33+
// Current CSV data state
34+
const currentCsvData = ref<CsvData | null>(null)
35+
3336
const {
3437
isReady,
3538
isLoading,
@@ -61,20 +64,69 @@ const runCode = async () => {
6164
}
6265
6366
const handleFileUpload = async (csvData: CsvData) => {
67+
currentCsvData.value = csvData
6468
await uploadCsvData(csvData)
6569
}
6670
6771
const handleFileRemoved = () => {
72+
currentCsvData.value = null
6873
// Clear any data-related variables in R
6974
void executeCode('if (exists("data")) rm(data)')
7075
}
7176
7277
const handleExampleSelect = async (example: RExample) => {
7378
code.value = example.code
74-
// Auto-execute the selected example
75-
if (isReady.value && example.code.trim()) {
76-
await executeCode(example.code)
77-
lastExecutedCode.value = example.code
79+
80+
// Wait for WebR to be ready before loading CSV
81+
if (!isReady.value) {
82+
console.log('WebR not ready yet, waiting...')
83+
return
84+
}
85+
86+
// Load CSV data if the example specifies a csvUrl
87+
if (example.csvUrl) {
88+
try {
89+
const response = await fetch(example.csvUrl)
90+
if (response.ok) {
91+
const csvContent = await response.text()
92+
const parseCsvInfo = (content: string) => {
93+
const lines = content.trim().split('\n')
94+
const columnNames = lines[0].split(',').map(name => name.trim().replace(/^"|"$/g, ''))
95+
return {
96+
rows: lines.length - 1,
97+
columns: columnNames.length,
98+
columnNames
99+
}
100+
}
101+
102+
const { rows, columns, columnNames } = parseCsvInfo(csvContent)
103+
const csvData = {
104+
name: example.csvUrl.split('/').pop() || 'data.csv',
105+
content: csvContent,
106+
rows,
107+
columns,
108+
columnNames
109+
}
110+
111+
// Upload the CSV data (this will load it into R as 'data')
112+
currentCsvData.value = csvData
113+
await uploadCsvData(csvData)
114+
115+
// Execute code after CSV is loaded
116+
if (example.code.trim()) {
117+
await executeCode(example.code)
118+
lastExecutedCode.value = example.code
119+
}
120+
}
121+
} catch (error) {
122+
console.error('Failed to load CSV for example:', error)
123+
}
124+
} else {
125+
// Execute code immediately for examples without CSV
126+
if (example.code.trim()) {
127+
await executeCode(example.code)
128+
lastExecutedCode.value = example.code
129+
}
78130
}
79131
}
80132
@@ -92,11 +144,8 @@ const fetchGitHubStars = async () => {
92144
}
93145
94146
onMounted(() => {
95-
void initializeWebR(code.value)
96-
// Set initial executed code after auto-execution
97-
setTimeout(() => {
98-
lastExecutedCode.value = code.value
99-
}, 100)
147+
// Initialize WebR without auto-executing the initial code
148+
void initializeWebR('')
100149
// Fetch GitHub stars
101150
void fetchGitHubStars()
102151
})
@@ -133,7 +182,11 @@ onMounted(() => {
133182
<main class="main">
134183
<div class="toolbar">
135184
<div class="toolbar-left">
136-
<FileUpload @file-uploaded="handleFileUpload" @file-removed="handleFileRemoved" />
185+
<FileUpload
186+
:uploaded-file="currentCsvData"
187+
@file-uploaded="handleFileUpload"
188+
@file-removed="handleFileRemoved"
189+
/>
137190
<ExampleSelector @example-selected="handleExampleSelect" />
138191
</div>
139192
<div class="toolbar-right">

src/components/ExampleSelector.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const handleExampleChange = () => {
5757
border-color: #9ca3af;
5858
}
5959
60+
6061
.select:focus {
6162
outline: none;
6263
border-color: #3b82f6;

0 commit comments

Comments
 (0)