|
| 1 | +# Simplification Ideas for webr-ggplot2 |
| 2 | + |
| 3 | +This document outlines opportunities to simplify the codebase while maintaining all functionality, making it easier to use as a starting point for others. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The goal is to reduce complexity by ~40% while keeping the same user experience. This will make the project more approachable for developers who want to: |
| 8 | +- Understand how WebR works |
| 9 | +- Build their own R-in-browser applications |
| 10 | +- Deploy quickly without configuration overhead |
| 11 | + |
| 12 | +## 1. Dependency Reduction |
| 13 | + |
| 14 | +### Remove Unnecessary Packages |
| 15 | +- `@monaco-editor/loader` - Monaco is imported directly, loader not needed |
| 16 | +- `@rushstack/eslint-patch` - Only needed for complex monorepo setups |
| 17 | +- `@tsconfig/node18` - Can use inline TypeScript configuration |
| 18 | +- `@vue/tsconfig` - Provides minimal value over direct configuration |
| 19 | +- All ESLint packages - While useful, adds complexity for a demo project |
| 20 | +- All Prettier packages - Can be optional for those who want it |
| 21 | +- `pnpm-workspace.yaml` - Single package project doesn't need workspace |
| 22 | + |
| 23 | +### Keep Only Essential Dependencies |
| 24 | +- `vue` - Core framework |
| 25 | +- `vite` - Build tool |
| 26 | +- `typescript` - Type safety |
| 27 | +- `webr` - R runtime in browser |
| 28 | +- `monaco-editor` - Code editor |
| 29 | +- `@vitejs/plugin-vue` - Vue support for Vite |
| 30 | + |
| 31 | +### Package Manager |
| 32 | +- Switch from pnpm to npm for simpler setup |
| 33 | +- Remove pnpm-specific configuration files |
| 34 | + |
| 35 | +## 2. Component Consolidation |
| 36 | + |
| 37 | +### Current Structure (6 components) |
| 38 | +``` |
| 39 | +components/ |
| 40 | +├── CodeEditor.vue |
| 41 | +├── ExampleSelector.vue |
| 42 | +├── FileUpload.vue |
| 43 | +├── LibrarySelector.vue |
| 44 | +├── OutputDisplay.vue |
| 45 | +└── WebRStatus.vue |
| 46 | +``` |
| 47 | + |
| 48 | +### Simplified Structure (4 components) |
| 49 | +``` |
| 50 | +components/ |
| 51 | +├── CodeEditor.vue # R code editor with examples dropdown |
| 52 | +├── OutputPanel.vue # Merged console + plots display |
| 53 | +├── StatusBar.vue # Merged WebR status + library info |
| 54 | +└── FileUpload.vue # CSV upload (unchanged) |
| 55 | +``` |
| 56 | + |
| 57 | +### Specific Merges |
| 58 | +- **WebRStatus + LibrarySelector → StatusBar**: Single component for all status info |
| 59 | +- **Console logic from App.vue → OutputPanel**: Centralize output handling |
| 60 | +- **ExampleSelector → CodeEditor**: Examples are part of the editor experience |
| 61 | + |
| 62 | +## 3. Configuration Simplification |
| 63 | + |
| 64 | +### TypeScript Configuration |
| 65 | +Replace 3 config files with single `tsconfig.json`: |
| 66 | +```json |
| 67 | +{ |
| 68 | + "compilerOptions": { |
| 69 | + "target": "ES2020", |
| 70 | + "module": "ESNext", |
| 71 | + "lib": ["ES2020", "DOM"], |
| 72 | + "jsx": "preserve", |
| 73 | + "moduleResolution": "node", |
| 74 | + "strict": true, |
| 75 | + "esModuleInterop": true, |
| 76 | + "skipLibCheck": true, |
| 77 | + "forceConsistentCasingInFileNames": true |
| 78 | + }, |
| 79 | + "include": ["src/**/*"], |
| 80 | + "exclude": ["node_modules"] |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Build Process |
| 85 | +- Remove `vue-tsc` type checking from build (keep for dev if desired) |
| 86 | +- Simplify scripts in package.json |
| 87 | +- Minimal vite.config.ts focused only on CORS headers for WebR |
| 88 | + |
| 89 | +### Remove Configuration Files |
| 90 | +- `.eslintrc.cjs` |
| 91 | +- `.prettierrc.json` |
| 92 | +- `tsconfig.app.json` |
| 93 | +- `tsconfig.node.json` |
| 94 | +- `pnpm-workspace.yaml` |
| 95 | + |
| 96 | +## 4. Code Pattern Improvements |
| 97 | + |
| 98 | +### Message Handling |
| 99 | +- Simplify message types to just: "output", "error", "plot" |
| 100 | +- Remove complex message filtering logic |
| 101 | +- Centralize all console handling in OutputPanel |
| 102 | + |
| 103 | +### Type Safety |
| 104 | +Replace `any` types with proper interfaces: |
| 105 | +- WebR instance typing |
| 106 | +- Message payload types |
| 107 | +- File upload event types |
| 108 | + |
| 109 | +### Remove Workarounds |
| 110 | +- Console.error override hack for WebR warnings |
| 111 | +- Complex Monaco worker configuration |
| 112 | +- Redundant state management between components |
| 113 | + |
| 114 | +### Library Management |
| 115 | +- Remove toggle functionality for libraries |
| 116 | +- Auto-install required packages (ggplot2, dplyr, ggrepel) on init |
| 117 | +- Simpler status display |
| 118 | + |
| 119 | +## 5. CSS and Styling |
| 120 | + |
| 121 | +### Current Issues |
| 122 | +- Duplicate styles across components |
| 123 | +- Inconsistent spacing and colors |
| 124 | +- Complex nested selectors |
| 125 | + |
| 126 | +### Improvements |
| 127 | +- Create CSS variables for consistent theming |
| 128 | +- Use utility classes for common patterns |
| 129 | +- Consolidate similar styles |
| 130 | +- Remove unused CSS |
| 131 | + |
| 132 | +## 6. Project Structure |
| 133 | + |
| 134 | +### Simplified Directory Layout |
| 135 | +``` |
| 136 | +webr-ggplot2/ |
| 137 | +├── src/ |
| 138 | +│ ├── components/ # 4 consolidated components |
| 139 | +│ ├── composables/ # Single useWebR.ts |
| 140 | +│ ├── data/ # examples.ts unchanged |
| 141 | +│ ├── types/ # Proper TypeScript interfaces |
| 142 | +│ ├── App.vue # Cleaner layout component |
| 143 | +│ ├── main.ts # Minimal setup |
| 144 | +│ └── style.css # Consolidated styles |
| 145 | +├── public/ # Static assets |
| 146 | +├── index.html # Entry point |
| 147 | +├── package.json # Simplified dependencies |
| 148 | +├── tsconfig.json # Single TS config |
| 149 | +├── vite.config.ts # Minimal Vite config |
| 150 | +└── README.md # Clear setup instructions |
| 151 | +``` |
| 152 | + |
| 153 | +## 7. Setup and Deployment |
| 154 | + |
| 155 | +### Current Setup |
| 156 | +```bash |
| 157 | +# Install pnpm |
| 158 | +npm install -g pnpm |
| 159 | +# Install dependencies |
| 160 | +pnpm install |
| 161 | +# Run dev server |
| 162 | +pnpm dev |
| 163 | +# Build |
| 164 | +pnpm build |
| 165 | +``` |
| 166 | + |
| 167 | +### Simplified Setup |
| 168 | +```bash |
| 169 | +# Install and run |
| 170 | +npm install |
| 171 | +npm run dev |
| 172 | + |
| 173 | +# Build |
| 174 | +npm run build |
| 175 | +``` |
| 176 | + |
| 177 | +### README Improvements |
| 178 | +- Quick start section at the top |
| 179 | +- Clear explanation of what WebR is |
| 180 | +- Simple deployment instructions |
| 181 | +- Links to WebR and ggplot2 documentation |
| 182 | + |
| 183 | +## 8. Code Examples |
| 184 | + |
| 185 | +### Simplified useWebR Composable |
| 186 | +- Remove redundant state |
| 187 | +- Cleaner initialization |
| 188 | +- Better error handling |
| 189 | +- Typed WebR instance |
| 190 | + |
| 191 | +### Cleaner App.vue |
| 192 | +- Remove console logic (moved to OutputPanel) |
| 193 | +- Simpler layout structure |
| 194 | +- Better responsive design |
| 195 | +- Cleaner event handling |
| 196 | + |
| 197 | +## 9. Benefits of Simplification |
| 198 | + |
| 199 | +### For Users |
| 200 | +- Faster setup (npm install && npm run dev) |
| 201 | +- Easier to understand codebase |
| 202 | +- Better starting point for customization |
| 203 | +- Fewer things that can go wrong |
| 204 | + |
| 205 | +### For Maintainers |
| 206 | +- Less dependencies to update |
| 207 | +- Clearer code structure |
| 208 | +- Easier to add features |
| 209 | +- Better performance |
| 210 | + |
| 211 | +### For Deployment |
| 212 | +- Smaller bundle size |
| 213 | +- Faster builds |
| 214 | +- Works out of the box |
| 215 | +- No configuration needed |
| 216 | + |
| 217 | +## 10. Implementation Priority |
| 218 | + |
| 219 | +1. **High Priority** |
| 220 | + - Remove unnecessary dependencies |
| 221 | + - Consolidate TypeScript configuration |
| 222 | + - Merge WebRStatus and LibrarySelector |
| 223 | + |
| 224 | +2. **Medium Priority** |
| 225 | + - Consolidate console handling |
| 226 | + - Simplify message types |
| 227 | + - Fix TypeScript types |
| 228 | + |
| 229 | +3. **Low Priority** |
| 230 | + - CSS improvements |
| 231 | + - README updates |
| 232 | + - Example refinements |
| 233 | + |
| 234 | +## Conclusion |
| 235 | + |
| 236 | +These simplifications will make webr-ggplot2 a cleaner, more approachable example of running R in the browser. The reduced complexity makes it an ideal starting point for developers wanting to build their own WebR-powered applications. |
0 commit comments