Embeddable code exercises with <code-cell>s

User Guide

Basic Usage

ckcode provides a simple interface for running code on a Jupyter server. Here is what a ckcode cell looks like:

# editor

The area at the top marked # editor is where you can type in R code. When you click the Run button, that code will be run. Try typing 1 + 1 on a new line and then click Run. You should see an output box appear below the buttons that has the number 2. After every Run, the output will always be shown at the bottom of the code cell. If you click Reset the output will be cleared and the editor text will be reset to where it was when you started.

When a code cell has a Submit button, that means that there is a solution for cell, and that your code will be tested against the solution. See if you can figure out how to solve the code cell below:

# write code that outputs the number 3 ex() %>% check_output_expr("3")

When you click the Run button on this cell, the code is run but not tested or submitted. However, when you click Submit the code is tested against a solution and tests to see if it is correct. Then you will get some feedback based on your answer. The feedback is shown in the blue box above the output. Try entering 1 + 1 and submitting it, and then 1 + 2.

It "remembers"

When you click Run or Submit, the cell will remember your response for next time. Try running some new code here, then refresh the page and you'll see your code was remembered. If you click Reset the code will go back to the original prompt.

# change me and run!

Hotkeys

If you prefer using a keyboard over the mouse, hotkeys are provided for each of the buttons (and one to move your browser focus back to the editor after a run).

Action Mac Windows / Linux
Run Cmd + Enter Ctrl + Enter
Submit Cmd + Shift + Enter Ctrl + Shift + Enter
Reset Cmd + Shift + r Ctrl + Shift + r
Focus editor Cmd + Shift + e Ctrl + Shift + e