Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions shiny/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ class App:
Example
-------

.. code-block:: python
```{python}
#| eval: false
from shiny import App, Inputs, Outputs, Session, ui

from shiny import App, Inputs, Outputs, Session, ui
app_ui = ui.page_fluid("Hello Shiny!")

app_ui = ui.page_fluid("Hello Shiny!")

def server(input: Inputs, output: Outputs, session: Session):
pass
def server(input: Inputs, output: Outputs, session: Session):
pass

app = App(app_ui, server)
app = App(app_ui, server)
```
"""

lib_prefix: str = "lib/"
Expand Down
22 changes: 11 additions & 11 deletions shiny/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,21 @@ def run_app(
Examples
--------

.. code-block:: python
```{python}
from shiny import run_app

from shiny import run_app
# Run ``app`` inside ``./app.py``
run_app()

# Run ``app`` inside ``./app.py``
run_app()
# Run ``app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
run_app("myapp")

# Run ``app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
run_app("myapp")
# Run ``my_app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
run_app("myapp:my_app")

# Run ``my_app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
run_app("myapp:my_app")

# Run ``my_app`` inside ``../myapp.py`` (or ``../myapp/app.py``)
run_app("myapp:my_app", app_dir="..")
# Run ``my_app`` inside ``../myapp.py`` (or ``../myapp/app.py``)
run_app("myapp:my_app", app_dir="..")
```
"""

# If port is 0, randomize
Expand Down
25 changes: 13 additions & 12 deletions shiny/input_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
if TYPE_CHECKING:
from .session import Session


from .types import ActionButtonValue

InputHandlerType = Callable[[Any, str, "Session"], Any]
Expand Down Expand Up @@ -74,21 +73,23 @@ def _process_value(self, type: str, value: Any, name: str, session: Session) ->

Example
-------
.. code-block:: python

from shiny.input_handler import input_handlers
@input_handlers.add("mypackage.intify")
def _(value, name, session):
return int(value)
```{python}
#| eval: false
from shiny.input_handler import input_handlers
@input_handlers.add("mypackage.intify")
def _(value, name, session):
return int(value)
```

On the Javascript side, the associated input binding must have a corresponding
``getType`` method:

.. code-block:: javascript

getType: function(el) {
return "mypackage.intify";
}
```{python}
#| eval: false
getType: function(el) {
return "mypackage.intify";
}
```
"""


Expand Down
41 changes: 22 additions & 19 deletions shiny/ui/_include_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ def include_js(
document, you can wrap it in ``head_content`` (in this case, just make sure you're
aware that the DOM probably won't be ready when the script is executed).

.. code-block:: python

ui.fluidPage(
head_content(ui.include_js("custom.js")),
)
```{python}
#| eval: false
ui.page_fluid(
ui.head_content(ui.include_js("custom.js")),
)

# Alternately you can inline Javscript by changing the method.
ui.fluidPage(
head_content(ui.include_js("custom.js", method = "inline")),
)
# Alternately you can inline Javscript by changing the method.
ui.page_fluid(
ui.head_content(ui.include_js("custom.js", method = "inline")),
)
```

See Also
--------
Expand Down Expand Up @@ -133,19 +134,21 @@ def include_css(
may result in a Flash of Unstyled Content (FOUC). To instead place the CSS in the
:func:`~ui.tags.head` of the document, you can wrap it in ``head_content``:

.. code-block:: python

from htmltools import head_content from shiny import ui
```{python}
#| eval: false
from htmltools import head_content
from shiny import ui

ui.fluidPage(
head_content(ui.include_css("custom.css")),
ui.page_fluid(
ui.head_content(ui.include_css("custom.css")),

# You can also inline css by passing a dictionary with a `style` element.
ui.div(
{"style": "font-weight: bold;"},
ui.p("Some text!"),
)
# You can also inline css by passing a dictionary with a `style` element.
ui.div(
{"style": "font-weight: bold;"},
ui.p("Some text!"),
)
)
```

See Also
--------
Expand Down