Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api(session)): Start process of making session arguments removed from API #793

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9abb547
Make `session` `MISSING_TYPE` and display warning if something is pro…
schloerke Oct 30, 2023
f73df95
Add api example app to show how session context works
schloerke Oct 30, 2023
876560a
All `server` to take only `input` as `output` and `session` are no lo…
schloerke Oct 30, 2023
3944a6d
Remove `@output` and `session` from server where possible
schloerke Oct 30, 2023
ab36b8b
Update docs for server to account for 1 or 3 params
schloerke Oct 30, 2023
772b114
Allow for external errors from shinywidgets in couple apps
schloerke Oct 30, 2023
65829a3
Merge branch 'main' into drop_fn_session_param
schloerke Dec 19, 2023
938e360
Update _deprecated.py
schloerke Dec 19, 2023
6e03710
Allow for shiny express warning in examples tests
schloerke Dec 19, 2023
1ca6917
Merge branch 'main' into drop_fn_session_param
schloerke Jan 8, 2024
fbe499d
Merge branch 'main' into drop_fn_session_param
schloerke Jan 10, 2024
6e2ca05
Merge branch 'main' into drop_fn_session_param
schloerke Jan 19, 2024
1159d1e
Merge followup
schloerke Jan 19, 2024
4d8cbc7
Update example_apps.py
schloerke Jan 19, 2024
25f9b71
Merge branch 'main' into drop_fn_session_param
schloerke Jan 31, 2024
5a4f8e2
Remove more output / server params where possible (after merge from `…
schloerke Feb 1, 2024
c520161
Merge branch 'main' into drop_fn_session_param
schloerke Feb 13, 2024
c926064
lints
schloerke Feb 13, 2024
e1715e2
Merge branch 'main' into drop_fn_session_param
schloerke Feb 14, 2024
e5e7525
Shorter error line for brownian app
schloerke Feb 14, 2024
a3f4605
Merge branch 'main' into drop_fn_session_param
schloerke Jun 3, 2024
c3fbd6b
Merge followup
schloerke Jun 3, 2024
9cd0ca7
Merge branch 'main' into drop_fn_session_param
schloerke Jun 3, 2024
9380053
Define type as explicitly None, not Optional
schloerke Jun 3, 2024
c7b73e7
Be sure all update methods and accordion methods do not drop `session…
schloerke Jun 3, 2024
86a7829
Add `session` back to `update_sidebar()`
schloerke Jun 3, 2024
ca91b25
Update _input_update.py
schloerke Jun 3, 2024
1cc75e6
Merge branch 'main' into drop_fn_session_param
schloerke Jun 3, 2024
188fce4
Update CHANGELOG.md
schloerke Jun 3, 2024
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
4 changes: 2 additions & 2 deletions examples/airmass/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from astropy.coordinates import AltAz, EarthLocation, SkyCoord
from location import location_server, location_ui

from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
from shiny import App, Inputs, reactive, render, req, ui

app_ui = ui.page_fixed(
ui.tags.h3("Air mass calculator"),
Expand Down Expand Up @@ -57,7 +57,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
loc = location_server("location")
time_padding = datetime.timedelta(hours=1.5)

Expand Down
4 changes: 2 additions & 2 deletions examples/annotation-export/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas as pd
import seaborn as sns

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
from shiny import App, Inputs, reactive, render, ui
from shiny.plotutils import brushed_points

path = Path(__file__).parent / "boulder_temp.csv"
Expand Down Expand Up @@ -38,7 +38,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
annotated_data = reactive.value(weather_df)

@reactive.calc
Expand Down
2 changes: 1 addition & 1 deletion examples/brownian/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)


def server(input, output, session):
def server(input):
# BROWNIAN MOTION ====

@reactive.calc
Expand Down
4 changes: 2 additions & 2 deletions examples/cpuinfo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np
import pandas as pd

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
from shiny import App, Inputs, reactive, render, ui

# The agg matplotlib backend seems to be a little more efficient than the default when
# running on macOS, and also gives more consistent results across operating systems
Expand Down Expand Up @@ -110,7 +110,7 @@ def cpu_current():
return cpu_percent(percpu=True)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
cpu_history = reactive.value(None)

@reactive.calc
Expand Down
4 changes: 2 additions & 2 deletions examples/dataframe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import seaborn as sns
from shinyswatch.theme import darkly

from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
from shiny import App, Inputs, reactive, render, req, ui


def app_ui(req):
Expand Down Expand Up @@ -59,7 +59,7 @@ def light_dark_switcher(dark):
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
df: reactive.value[pd.DataFrame] = reactive.value()

@reactive.effect
Expand Down
2 changes: 1 addition & 1 deletion examples/duckdb/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def load_csv(con, csv_name, table_name):
)


def server(input, output, session):
def server(input):
mod_counter = reactive.value(0)

query_output_server("initial_query", con=con, remove_id="initial_query")
Expand Down
4 changes: 2 additions & 2 deletions examples/event/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
from shiny import App, Inputs, reactive, render, ui

app_ui = ui.page_fluid(
ui.tags.p(
Expand All @@ -26,7 +26,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@reactive.effect
@reactive.event(input.btn)
def _():
Expand Down
4 changes: 2 additions & 2 deletions examples/global_pyplot/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import matplotlib.pyplot as plt

from shiny import App, Inputs, Outputs, Session, render, ui
from shiny import App, Inputs, render, ui

app_ui = ui.page_fluid(
ui.input_checkbox("render", "Render", value=True),
Expand All @@ -18,7 +18,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@render.plot
def mpl():
if input.render():
Expand Down
4 changes: 2 additions & 2 deletions examples/inputs-update/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import date

from shiny import App, Inputs, Outputs, Session, reactive, ui
from shiny import App, Inputs, reactive, ui

app_ui = ui.page_fluid(
ui.panel_title("Changing the values of inputs from the server"),
Expand Down Expand Up @@ -87,7 +87,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@reactive.effect
def _():
# We'll use these multiple times, so use short var names for
Expand Down
4 changes: 2 additions & 2 deletions examples/model-score/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from plotly_streaming import render_plotly_streaming
from shinywidgets import output_widget

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
from shiny import App, Inputs, reactive, render, ui

THRESHOLD_MID = 0.85
THRESHOLD_MID_COLOR = "rgb(0, 137, 26)"
Expand Down Expand Up @@ -137,7 +137,7 @@ def app_ui(req):
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@reactive.calc
def recent_df():
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/moduleapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def dynamic_counter():
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
counter_server("counter1")
counter_wrapper_server("counter2_wrapper", "Counter 2")

Expand Down
4 changes: 2 additions & 2 deletions examples/penguins/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seaborn as sns
from colors import bg_palette, palette

from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
from shiny import App, Inputs, reactive, render, req, ui

sns.set_theme()

Expand Down Expand Up @@ -52,7 +52,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@reactive.calc
def filtered_df() -> pd.DataFrame:
"""Returns a Pandas data frame that includes only the desired rows"""
Expand Down
4 changes: 2 additions & 2 deletions examples/req/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
from shiny import App, Inputs, reactive, render, req, ui
from shiny.types import SafeException

app_ui = ui.page_fluid(
Expand All @@ -15,7 +15,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@reactive.calc
def safe_click():
req(input.safe())
Expand Down
4 changes: 2 additions & 2 deletions examples/static_plots/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seaborn as sns
from plotnine.data import mtcars

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
from shiny import App, Inputs, reactive, render, ui

nav = ui.navset_pill_list(
ui.nav_control(ui.p("Choose a package", class_="lead text-center")),
Expand Down Expand Up @@ -53,7 +53,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@reactive.calc
def fake_data():
n = 5000
Expand Down
4 changes: 2 additions & 2 deletions examples/typed_inputs/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import typing

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
from shiny import App, Inputs, reactive, render, ui

app_ui = ui.page_fluid(
ui.input_numeric("n", "N", 20),
Expand All @@ -24,7 +24,7 @@ class ShinyInputs(Inputs):
check: reactive.value[bool]


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
# Cast `input` to our ShinyInputs class. This just tells the static type checker
# that we want it treated as a ShinyInputs object for type checking; it has no
# run-time effect.
Expand Down
4 changes: 2 additions & 2 deletions examples/ui-func/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from starlette.requests import Request

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
from shiny import App, Inputs, reactive, render, ui


def app_ui(request: Request):
Expand All @@ -12,7 +12,7 @@ def app_ui(request: Request):
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@render.text
def now():
reactive.invalidate_later(0.1)
Expand Down
6 changes: 4 additions & 2 deletions shiny/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ class App:
returns a UI definition, if you need the UI definition to be created dynamically
for each pageview.
server
A function which is called once for each session, ensuring that each session is
independent.
A function which is called once for each session, ensuring that each app is
independent. This function can either take one positional argument (``input:
Inputs``) or three positional arguments (``input: Inputs``, ``output:Outputs``,
``session: Session``).
static_assets
Static files to be served by the app. If this is a string or Path object, it
must be a directory, and it will be mounted at `/`. If this is a dictionary,
Expand Down
26 changes: 24 additions & 2 deletions shiny/_deprecated.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import warnings
from typing import Any

from . import reactive, render

__all__ = (
"render_text",
"render_plot",
Expand All @@ -29,29 +27,53 @@ def warn_deprecated(message: str):

def render_text():
"""Deprecated. Please use render.text() instead of render_text()."""
import shiny.render as render

warn_deprecated("render_text() is deprecated. Use render.text() instead.")
return render.text()


def render_ui():
"""Deprecated. Please use render.ui() instead of render_ui()."""
import shiny.render as render

warn_deprecated("render_ui() is deprecated. Use render.ui() instead.")
return render.ui()


def render_plot(*args: Any, **kwargs: Any): # type: ignore
"""Deprecated. Please use render.plot() instead of render_plot()."""
import shiny.render as render

warn_deprecated("render_plot() is deprecated. Use render.plot() instead.")
return render.plot(*args, **kwargs) # type: ignore


def render_image(*args: Any, **kwargs: Any): # type: ignore
"""Deprecated. Please use render.image() instead of render_image()."""
import shiny.render as render

warn_deprecated("render_image() is deprecated. Use render.image() instead.")
return render.image(*args, **kwargs) # type: ignore


def event(*args: Any, **kwargs: Any):
"""Deprecated. Please use @reactive.event() instead of @event()."""
import shiny.reactive as reactive

warn_deprecated("@event() is deprecated. Use @reactive.event() instead.")
return reactive.event(*args, **kwargs)


def session_type_warning() -> None:
warn_deprecated(
"`session=` is deprecated. Please call with no `session=` argument as this parameter will be removed in the near future. If you need to pass a session, use your code inside a `with session_context(session):`."
)


_session_param_docs = """
session
Deprecated. If a custom :class:`~shiny.Session` is needed, please execute your
code inside `with shiny.session.session_context(session):`. See
:func:`~shiny.session.session_context` for more details.
"""
2 changes: 1 addition & 1 deletion shiny/api-examples/Module/app-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def out() -> str:
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
counter_server("counter1")
counter_server("counter2")

Expand Down
4 changes: 2 additions & 2 deletions shiny/api-examples/Progress/app-core.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import asyncio

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
from shiny import App, Inputs, reactive, render, ui

app_ui = ui.page_fluid(
ui.input_action_button("button", "Compute"),
ui.output_text("compute"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@render.text
@reactive.event(input.button)
async def compute():
Expand Down
4 changes: 2 additions & 2 deletions shiny/api-examples/Renderer/app-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Import the custom renderer implementations
from renderers import render_capitalize, render_upper

from shiny import App, Inputs, Outputs, Session, ui
from shiny import App, Inputs, ui

app_ui = ui.page_fluid(
ui.h1("Capitalization renderer"),
Expand All @@ -19,7 +19,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
# Hovering over `@render_upper` will display the class documentation
@render_upper
def upper():
Expand Down
4 changes: 2 additions & 2 deletions shiny/api-examples/SafeException/app-core.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from shiny import App, Inputs, Outputs, Session, render, ui
from shiny import App, Inputs, render, ui
from shiny.types import SafeException

app_ui = ui.page_fluid(ui.output_ui("safe"), ui.output_ui("unsafe"))


def server(input: Inputs, output: Outputs, session: Session):
def server(input: Inputs):
@render.ui
def safe():
raise SafeException("This is a safe exception")
Expand Down
Loading
Loading