Skip to content

Notebooks, scripts and Quarto documents

Read project data from Python or R, send a result card back to the app, and spot stale cells before they fool you.

Introductory ~9 min9 steps

What runs in CodeSplash

You will be able to

  • Create a notebook, script or document and load a dataset into it
  • Turn an analysis into a notebook from its Code tab
  • Find cells whose results no longer match their code

Read first

01

When a dialog isn't enough

Read

Analyze covers methods with a setup. Notebooks (⌘9) is for everything else: your own code, in Python or R, against the same project data.

New offers six kinds of file:

  • Python notebook and R notebook (.ipynb)
  • Python script (.py) and R script (.R)
  • Quarto document (.qmd) and R Markdown document (.Rmd)

They are ordinary files in your project folder, so they work outside the app too.

02

Read your data

In the app

Create a notebook in the language you prefer and run a cell like this. cs.table and cs_table read a dataset by name from the project warehouse.

Python
import codesplash as cs

df = cs.table("Palmer penguins (sample)").df()
df.groupby("species")["body_mass"].mean()
R
library(codesplashr)

df <- cs_table("Palmer penguins (sample)")
aggregate(body_mass ~ species, df, mean)

Cells are Code, Markdown or SQL. A SQL cell queries the warehouse directly and can bind its result to a variable. Run a cell with ⌘↵; ⇧↵ also moves to the next one.

03

Start from a working analysis

In the app

You rarely need to start from an empty notebook. On any analysis, open Code and press Open as notebook. The generated Python or R arrives as cells you can change.

That's how you go past what a dialog offers without rewriting anything. The generated code uses ordinary libraries, plus cs.publish to send a result card back.

04

What can go wrong?

Predict

Predict first

You change a cell near the top of a notebook that filters your data, and you don't re-run the rest. The charts below are still on the page. Do they reflect your new filter?

Yes, numbers on the page are currentNo, they might be stale
Reveal

No. Outputs stay where they were until their cell runs again, and a notebook shows you an old answer with no warning of its own. CodeSplash tracks this: More ways to run can run the cells whose code changed, that depend on a cell that re-ran, or that ran before the kernel restarted.

05

Keep it reproducible

Explore

Try this. Run two cells, where the second uses a variable from the first. Edit the first cell without running it, then open More ways to run and run only the stale cells.

Then use Run all cells, which runs from the top and stops at the first error. If your notebook only works when run out of order, that's what you'll discover here.

Version history keeps snapshots on save and before Run all, so an experiment you regret is one restore away.

06

The side panels

Read

Beside the cells you'll find Variables (what's in the kernel now, with a viewer for data frames), Outline (headings), and Help (documentation for what's under the cursor).

A notebook runs in its own kernelEngineThe Python or R process that runs an analysis; both produce the same result card., the process holding your variables. Restart clears them, which is the fastest way to find out what your notebook secretly depends on. Scripts run in a fresh process each time, so they can't have that problem.

07

Check your understanding

Checkpoint

Check yourself

Which line reads a project dataset into R?

Show the answer

Answer: b

Datasets live in the project warehouse. cs_table (Python: cs.table) reads them by name, and cs_publish sends results the other way.

Check yourself

Put these in order to check a notebook really reproduces.

  1. 1Press Run all cells
  2. 2Compare the results with what you reported
  3. 3Restart the kernel

Show the answer

The order:

  1. Restart the kernel
  2. Press Run all cells
  3. Compare the results with what you reported

Restarting clears hidden state; running from the top shows whether the order on the page is enough to reach your result.

08

Choose your format

Reflect

Which fits your next piece of work: a notebook for exploring, a script for something that runs on a schedule, or a Quarto document for prose with results in it? If you're not sure, start with a notebook. Convert and Export in the file's menu can move it later.

To share a notebook with someone who doesn't use CodeSplash, Export… in its toolbar saves it as an HTML page, a PDF or a Jupyter notebook (.ipynb).

09

Recap

Recap
  • Notebooks, scripts and documents use your project's data through cs.table / cs_table.
  • Open as notebook on any analysis's Code tab is the quickest way past a dialog.
  • Outputs can go stale. Run the stale cells, or restart and run all.

Concepts in this lesson