Skip to content

Commit ccca241

Browse files
authored
Fix example code blocks (#626)
1 parent f2e0535 commit ccca241

File tree

4 files changed

+54
-49
lines changed

4 files changed

+54
-49
lines changed

shiny/_app.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ class App:
5353
Example
5454
-------
5555
56-
.. code-block:: python
56+
```{python}
57+
#| eval: false
58+
from shiny import App, Inputs, Outputs, Session, ui
5759
58-
from shiny import App, Inputs, Outputs, Session, ui
60+
app_ui = ui.page_fluid("Hello Shiny!")
5961
60-
app_ui = ui.page_fluid("Hello Shiny!")
61-
62-
def server(input: Inputs, output: Outputs, session: Session):
63-
pass
62+
def server(input: Inputs, output: Outputs, session: Session):
63+
pass
6464
65-
app = App(app_ui, server)
65+
app = App(app_ui, server)
66+
```
6667
"""
6768

6869
lib_prefix: str = "lib/"

shiny/_main.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,21 @@ def run_app(
207207
Examples
208208
--------
209209
210-
.. code-block:: python
210+
```{python}
211+
from shiny import run_app
211212
212-
from shiny import run_app
213+
# Run ``app`` inside ``./app.py``
214+
run_app()
213215
214-
# Run ``app`` inside ``./app.py``
215-
run_app()
216+
# Run ``app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
217+
run_app("myapp")
216218
217-
# Run ``app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
218-
run_app("myapp")
219+
# Run ``my_app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
220+
run_app("myapp:my_app")
219221
220-
# Run ``my_app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
221-
run_app("myapp:my_app")
222-
223-
# Run ``my_app`` inside ``../myapp.py`` (or ``../myapp/app.py``)
224-
run_app("myapp:my_app", app_dir="..")
222+
# Run ``my_app`` inside ``../myapp.py`` (or ``../myapp/app.py``)
223+
run_app("myapp:my_app", app_dir="..")
224+
```
225225
"""
226226

227227
# If port is 0, randomize

shiny/input_handler.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
if TYPE_CHECKING:
1111
from .session import Session
1212

13-
1413
from .types import ActionButtonValue
1514

1615
InputHandlerType = Callable[[Any, str, "Session"], Any]
@@ -74,21 +73,23 @@ def _process_value(self, type: str, value: Any, name: str, session: Session) ->
7473
7574
Example
7675
-------
77-
.. code-block:: python
78-
79-
from shiny.input_handler import input_handlers
80-
@input_handlers.add("mypackage.intify")
81-
def _(value, name, session):
82-
return int(value)
76+
```{python}
77+
#| eval: false
78+
from shiny.input_handler import input_handlers
79+
@input_handlers.add("mypackage.intify")
80+
def _(value, name, session):
81+
return int(value)
82+
```
8383
8484
On the Javascript side, the associated input binding must have a corresponding
8585
``getType`` method:
8686
87-
.. code-block:: javascript
88-
89-
getType: function(el) {
90-
return "mypackage.intify";
91-
}
87+
```{python}
88+
#| eval: false
89+
getType: function(el) {
90+
return "mypackage.intify";
91+
}
92+
```
9293
"""
9394

9495

shiny/ui/_include_helpers.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,17 @@ def include_js(
6363
document, you can wrap it in ``head_content`` (in this case, just make sure you're
6464
aware that the DOM probably won't be ready when the script is executed).
6565
66-
.. code-block:: python
67-
68-
ui.fluidPage(
69-
head_content(ui.include_js("custom.js")),
70-
)
66+
```{python}
67+
#| eval: false
68+
ui.page_fluid(
69+
ui.head_content(ui.include_js("custom.js")),
70+
)
7171
72-
# Alternately you can inline Javscript by changing the method.
73-
ui.fluidPage(
74-
head_content(ui.include_js("custom.js", method = "inline")),
75-
)
72+
# Alternately you can inline Javscript by changing the method.
73+
ui.page_fluid(
74+
ui.head_content(ui.include_js("custom.js", method = "inline")),
75+
)
76+
```
7677
7778
See Also
7879
--------
@@ -133,19 +134,21 @@ def include_css(
133134
may result in a Flash of Unstyled Content (FOUC). To instead place the CSS in the
134135
:func:`~ui.tags.head` of the document, you can wrap it in ``head_content``:
135136
136-
.. code-block:: python
137-
138-
from htmltools import head_content from shiny import ui
137+
```{python}
138+
#| eval: false
139+
from htmltools import head_content
140+
from shiny import ui
139141
140-
ui.fluidPage(
141-
head_content(ui.include_css("custom.css")),
142+
ui.page_fluid(
143+
ui.head_content(ui.include_css("custom.css")),
142144
143-
# You can also inline css by passing a dictionary with a `style` element.
144-
ui.div(
145-
{"style": "font-weight: bold;"},
146-
ui.p("Some text!"),
147-
)
145+
# You can also inline css by passing a dictionary with a `style` element.
146+
ui.div(
147+
{"style": "font-weight: bold;"},
148+
ui.p("Some text!"),
148149
)
150+
)
151+
```
149152
150153
See Also
151154
--------

0 commit comments

Comments
 (0)