Run the Code in Notebook
Learn how to run code in your NikaWorkspace notebooks with multiple execution methods, streaming output, and powerful debugging features. Code execution is streamed from the kernel, allowing you to close the workspace and return later to see results.Step 1: Run Individual Code Blocks
Method 1: Hover Menu Run Button
- Hover Over Code Block: Hover over any code block
- Click Run Button: Click the play button (▶️) that appears in the hover menu
- Code Executes: Code runs and output streams in below the block
- Status Updates: Green checkmark shows successful execution
Method 2: Keyboard Shortcut
- Select Code Block: Click on the code block you want to run
- Press Shift+Enter: Use the keyboard shortcut to execute
- Code Executes: Code runs and cursor moves to next block
- View Results: See streaming output in real-time

Step 2: Run All Code Blocks
Run All Feature
- Click “Run All”: Use the “Run All” button in the top-right toolbar
- Sequential Execution: All codeNo Dragging Required blocks execute in order from top to bottom
- Progress Tracking: Watch as each block executes in sequence
- Complete Execution: All blocks finish with results displayed
Clear All Outputs
- Click “Clear All Outputs”: Remove all execution results
- Fresh Start: Start with clean output areas
- Re-run: Execute blocks again as needed

Step 3: Handle Exceptions and Errors
Exception Display
When code encounters errors:- Detailed Error Messages: Full exception details are displayed
- Traceback Information: Complete stack trace for debugging
- Error Context: Shows exactly where the error occurred
- Helpful Details: Error messages provide debugging guidance
AI-Powered Debugging
- “Resolve in GAIA” Button: Click to get AI assistance with errors
- Smart Suggestions: AI provides code fixes and explanations
- Context-Aware Help: AI understands your notebook context
- Learn More: See AI Coding in Notebook for detailed AI features

Step 4: Code Quality Features
Real-Time Code Linting
- Syntax Checking: Python syntax is checked after each line change
- Error Highlighting: Syntax errors are highlighted immediately
- Best Practices: Suggestions for code improvements
- Instant Feedback: Get feedback as you type
Autocompletion (Coming Soon)
- Tab Key Trigger: Press Tab to trigger code completion
- Context-Aware: Suggestions based on notebook context
- Smart Predictions: AI-powered code completion
- Variable Recognition: Understands variables in your notebook
Step 5: Reorder Code Blocks
Easy Block Reordering
- Use Arrow Buttons: Click up/down arrow buttons in block toolbar
- Shift Blocks: Move blocks up or down without dragging
- Visual Feedback: See blocks move in real-time
- Maintain Order: Keep logical flow of your analysis
Block Management
- Shift Up: Move block to previous position
- Shift Down: Move block to next position
- Dragging: Dragging block for reordering in a longer range
- Preserve Output: Block outputs move with the code

Step 6: Streaming Execution
Background Execution
- Streaming Output: Results stream in real-time from kernel
- Leave and Return: Close workspace, return hours later
- Persistent Execution: Long-running code continues in background
- Output Preservation: All results are saved and displayed
Long-Running Tasks
Benefits of Streaming
- No Time Pressure: Start long tasks and walk away
- Resource Efficiency: Use compute resources effectively
- Progress Monitoring: Check progress when you return
- Reliable Execution: No interruption from browser closure
Step 7: Code Execution Examples
Basic Code Execution
Library Installation
Error Handling Example
Best Practices
Code Organization
- Logical Flow: Arrange blocks in logical order
- Clear Comments: Add comments to explain your code
- Modular Code: Break complex tasks into smaller blocks
- Error Handling: Use try-catch blocks for robust code
Execution Strategy
- Test Small: Run small code blocks first
- Incremental Development: Build analysis step by step
- Save Results: Save intermediate results for long tasks
- Monitor Resources: Keep track of memory and CPU usage
Performance Tips
- Use Streaming: Leverage background execution for long tasks
- Efficient Code: Write optimized, vectorized code
- Batch Processing: Process data in manageable chunks
- Resource Management: Clean up large variables when done
Troubleshooting
Common Issues
- Code Not Running: Check if VM is started and ready
- Syntax Errors: Use the real-time linting to catch errors
- Long Execution: Use streaming execution for background tasks
- Memory Issues: Clear outputs or restart VM if needed
Solutions
- Restart VM: Stop and restart if VM becomes unresponsive
- Clear Outputs: Use “Clear All Outputs” to free memory
- AI Debugging: Use GAIA for help with complex errors
- Contact Support: Get help for persistent issues
Next Steps
Now that you can run code effectively:- AI Assistance: Learn about AI Coding in Notebook for debugging
- Install Libraries: Check Supported Python Libraries
- Start Machine: Learn about Starting Your Machine
- Publish Results: Publish Your Notebook to share your work
Get Expert Help
Talk to a Geospatial Expert
Need help with your geospatial projects? Our team of experts is here to assist you with implementation, best practices, and technical support.
Other ways to get help:
- Guides: Use the /guides tab for detailed tutorials
- Community: Ask questions in our community forum
- Support: Send us a support request