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

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Oct 30, 2023

Related to #790

  • Update session to have type MISSING_TYPE in functions where it could be resolved by using with session_context(sess):
  • Remove @output and session from server definitions in examples (where possible)
  • Changelog entry

App examples

Before:

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

app_ui = ui.page_fluid(
    ui.input_slider("controller", "Controller", min=0, max=1, value=0, step=1),
    ui.input_checkbox("inCheckbox", "Input checkbox"),
    ui.output_text_verbatim("txt", placeholder = True),
)


def server(input: Inputs, output: Outputs, session: Session):
    @reactive.Effect
    def _():
        # True if controller is odd, False if even.
        x_even = input.controller() % 2 == 1
        ui.update_checkbox("inCheckbox", value=x_even)

    @output
    @render.text
    def txt():
        return str(input.controller())

app = App(app_ui, server)

After:

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

app_ui = ui.page_fluid(
    ui.input_slider("controller", "Controller", min=0, max=1, value=0, step=1),
    ui.input_checkbox("inCheckbox", "Input checkbox"),
    ui.output_text_verbatim("txt", placeholder=True),
)


def server(input: Inputs):
    @reactive.Effect
    def _():
        # True if controller is odd, False if even.
        x_even = input.controller() % 2 == 1
        ui.update_checkbox("inCheckbox", value=x_even)

    @render.text
    def txt():
        return str(input.controller())


app = App(app_ui, server)

@schloerke schloerke requested a review from wch October 30, 2023 19:08
@schloerke schloerke self-assigned this Oct 30, 2023
@schloerke schloerke added this to the v0.8.0 milestone Dec 18, 2023
* main: (76 commits)
  Add shiny/templates to MANIFEST.in files (#926)
  docs: Function Reference Proofreads (#919)
  Fix failing deploy tests (#925)
  Add GitHub sources to shiny create
  Make changelog styling more consistent
  Function reference edits (#857)
  docs: Use definition lists for parameter descriptions to enable full markdown support (#901)
  docs(layout_columns): Add example app (#903)
  fix(layout_columns): Remove use of enum for breakpoints (#912)
  Express: don't automatically put strings in a `<pre>` block (#905)
  Deprecate `nav()` in favor of `nav_panel()` (#876)
  chore: Remove unused import
  refactor(layout_column_wrap): Use helper for wrapping children (#910)
  fix(layout_columns): Don't apply fillable class to layout container (#909)
  Add output to React template (#908)
  fix(layout_columns): Add missing `bslib-mb-spacing` class (#906)
  Custom component template updates (#874)
  fix(layout_columns): If the breakpoint name is an enum, need to collect the value (#902)
  chore: exclude `_dev/` folder (#897)
  feat: Add `ui.layout_columns()` (#856)
  ...
* main: (24 commits)
  Use dynamic version of py-shiny for deploy tests (#970)
  Add underscores to hide some imports (#978)
  Add rsconnect json files(shinyapps.io tests) and folium tests (#928)
  Express' `value_box()` no longer includes named positional args (#966)
  Include `tooltip()` and `popover()` in express (#949)
  Remove extra call to run_express()
  Call `tagify()` early to intercept `AttributeErrors` (#941)
  Don't pass sidebar twice to navbar_page
  Update changelog
  Update changelog
  Switch from `requests` to `urllib` (#940)
  Bump version to 0.6.1.1
  Fix docstring for page_opts
  Fix API doc sections for Express
  Smarter, lazier, and more complete page default/api for express (#893)
  Change `express.layout` to `express.ui` (#904)
  Remove `@output` from examples (#790)
  feat: Allow for `App` `server=` to take `input` only (#920)
  Add fixes for type stub generation (#828)
  Move quarto express docs to bottom
  ...
@schloerke schloerke marked this pull request as ready for review January 8, 2024 21:00
This was referenced Jan 10, 2024
@wch wch removed this from the v0.7.0 milestone Jan 16, 2024
@schloerke schloerke added this to the v0.8.0 milestone Jan 17, 2024
* main: (26 commits)
  api!: Merge RendererBase class into Renderer (#1032)
  chore(render.display): Improve error message (#1020)
  `express.ui.page_opts(title = ...)` now always generates a header (#1016)
  api!: `Renderer.auto_output_ui()` drops `id` arg. Make `RendererBase.output_id` a non-namespaced value. (#1030)
  fix(page_sidebar): Add semicolon to end style declaration (#1027)
  chore: Remove experimental from app (#1028)
  chore: Expose `render.renderer.RendererBaseT` and do not require `| None` when defining Renderer types (#1026)
  bug: Restore legacy renderers while packages transition (#1023)
  Update deploy test apps to use render.code
  Update changelog
  Provide useful message in Express when `input` was not imported (#994)
  Calculate coordinate mapping after drawing figure (#999)
  Remove `express.ui.output_*` functions, add `shiny.express.render` (#1018)
  fix: Do not allow for renderer's to be given to reactive effects (#1017)
  Truncate the requirements.txt file before deploys (#998)
  Update changelog
  Fixes for flake8 (#1012)
  Pin starlette version below 0.35 (#1009)
  Remove shiny express warning
  Cause RecallContextManagers to run when used without `with` (#992)
  ...
* main: (33 commits)
  test: Test apps locally before deploying via pytest fixtures. (#1055)
  docs: Add ExtendedTask to API index (#1088)
  Fix `render.download` in Shiny Express, take 2 (#1085)
  Bump version to 0.7.0.9000
  Create two different api doc folders, one for Core and one for Express (#1053)
  chore: Pin black to version 23 (#1077)
  chore: Remove github link to shinylive (#1069)
  Bump version to 0.7.0
  Raise when `express.[input,output,session]` are used outside of Express app (#1067)
  Update dashboard template (#1056)
  chore: Remove many broken quartodoc links (#1061)
  Update {bslib} (#1062)
  Update docstrings for `expressify`, `hold`, and `render.express` (#1066)
  Add `fill` to `__all__` in `ui` and `express.ui` (#1064)
  Update shiny.js (#1059)
  docs(examples): Use refactored shinylive syntax (#1048)
  Update `shiny.js` (#1052)
  Add `express.ui.panel_title` (#1039)
  Don't run `effect`s created in a `MockSession` (#1049)
  Delete shiny/api-examples/Calc directory (#1044)
  ...
* main:
  Bump version to 0.7.1.9000
  Fix input_task_button for modules (#1108)
  Bump version to 0.7.1
  Test input task button and extended task decorator (#1099)
  Add remaining examples for express API reference (#1093)
  test: Add `make playwright-debug` to help debug playwright tests (#1097)
  Make input_selectize work correctly within a module (#1091)
  Update types to allow `navset_*` functions to accept `MetadataNode` args (#1094)
  Update changelog
  Update express.ui.hold() to accept any type of object (#1089)
@wch wch removed this from the v0.8.0 milestone Mar 1, 2024
@wch wch added this to the v0.9.0 milestone Mar 1, 2024
@schloerke schloerke modified the milestones: v0.9.0, v0.10.0 May 8, 2024
* main: (185 commits)
  Resolve path to file when running Shiny Express apps (#1442)
  Fix changelog formatting
  test(conftest): Refactor conftest and controls to be imported as shiny.test module (#1413)
  `make install` shouldn't assume it has `setuptools` (#1437)
  test(browsers): Unskip webkit tests (#1431)
  chore: update shiny-vscode extension ID (#1434)
  Add setuptools as an install requirement in Python 3.12 and above (#1435)
  Bump version to 0.10.2.9000
  v0.10.2 release candidate
  Use `output_code()` and `render.code()` (#1421)
  Fix: spinners only show for a split second (#1429)
  Bump version to 0.10.1.9000
  Bump version to 0.10.1
  Update CHANGELOG.md (#1419)
  Update cpu info example
  bug(CI): Only update the shiny submodule when making the dev docs (#1417)
  Update shiny CSS (#1415)
  Bump version to 0.10.0.9000 for development
  Bump version to 0.10.0
  Update shiny JS/CSS assets (#1406)
  ...
* main:
  feat(data frame): Add `.data_view_rows()`, `.sort()`, `.filter()`, `.update_sort()`, and `.update_filter()`; `cell_selection()` no longer returns `None` (#1374)
…` in PR. Use active session around `session_on_flush_send_msg()`
Comment on lines +336 to +348
cur_session: Session | MISSING_TYPE | None = None

if isinstance(session, MISSING_TYPE):
from ..session import get_current_session

# If no session is provided, autodetect the current session (this
# could be None if outside of a session).
session = get_current_session()
cur_session = get_current_session()
else:
# Display warning that they should use `session_context()`
session_type_warning()
# Use current session value
cur_session = session
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only section that did not use active_session = require_active_session() cadence as an active session isn't required given the code.

I'd argue a session should be required to call invalidate_later(delay)

@schloerke schloerke requested review from wch and removed request for wch June 3, 2024 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants