MCPcopy
hub / github.com/marimo-team/marimo / show_code

Function show_code

marimo/_output/show_code.py:35–114  ·  view source on GitHub ↗

Display an output along with the code of the current cell. Use `mo.show_code` to show the code of the current cell along with the cell's output. This is useful if you want a cell's code to appear in the app preview or when running the notebook as an app with `marimo run`. In th

(
    output: object = None, *, position: Literal["above", "below"] = "below"
)

Source from the content-addressed store, hash-verified

33
34
35def show_code(
36 output: object = None, *, position: Literal["above", "below"] = "below"
37) -> Html:
38 """Display an output along with the code of the current cell.
39
40 Use `mo.show_code` to show the code of the current cell along with
41 the cell's output. This is useful if you want a cell's code to
42 appear in the app preview or when running the notebook as an app
43 with `marimo run`.
44
45 In the displayed code, all occurrences of mo.show_code(...) will be
46 replaced with ...
47
48 Show code that produces the output `factorial(5)`:
49
50 ```python
51 def factorial(n: int) -> int:
52 if n == 0:
53 return 1
54 return n * factorial(n - 1)
55
56
57 mo.show_code(factorial(5))
58 ```
59
60 Show code of a cell, without an output:
61
62 ```python
63 def factorial(n: int) -> int:
64 if n == 0:
65 return 1
66 return n * factorial(n - 1)
67
68
69 mo.show_code()
70 ```
71
72 Args:
73 output: the output to display with the cell's code; omit the output
74 to just show the cell's code.
75 position: Where to display the code relative to the output.
76 Use "above" to show code above the output, or "below" (default) to show
77 code below the output.
78
79 Returns:
80 HTML of the `output` arg displayed with its code.
81 """
82 assert position in ["above", "below"], (
83 "position must be 'above' or 'below'"
84 )
85
86 try:
87 context = get_context()
88 except ContextNotInitializedError:
89 return as_html(output)
90
91 cell_id = context.cell_id
92 if cell_id is None:

Callers 1

Calls 5

get_contextFunction · 0.90
as_htmlFunction · 0.90
vstackFunction · 0.90
code_editorClass · 0.90

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…