From 1c18794176ee665e776a69edeaf9a6cd85567924 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Tue, 19 Dec 2023 10:35:12 -0800 Subject: [PATCH 1/5] Add rsconnect json files and folium tests --- setup.cfg | 1 + shiny/api-examples/render_display/app.py | 19 ++++++++++++ .../rsconnect-python/plotly_app.json | 13 ++++---- .../shiny-express-accordion.json | 11 +++++++ .../apps/shiny-express-dataframe/app.py | 24 ++++++++++++++ .../shiny-express-dataframe/requirements.txt | 3 ++ .../shiny-express-dataframe.json | 11 +++++++ .../deploys/apps/shiny-express-folium/app.py | 30 ++++++++++++++++++ .../shiny-express-folium/requirements.txt | 3 ++ .../shiny-express-folium.json | 11 +++++++ .../shiny-express-page-default.json | 11 +++++++ .../shiny-express-page-fillable.json | 11 +++++++ .../shiny-express-page-fluid.json | 11 +++++++ .../shiny-express-page-sidebar.json | 11 +++++++ .../deploys/tests/test_accordion.py | 2 +- .../deploys/tests/test_dataframe.py | 22 +++++++++++++ tests/playwright/deploys/tests/test_folium.py | 22 +++++++++++++ .../deploys/tests/test_page_default.py | 2 +- .../deploys/tests/test_page_fillable.py | 2 +- .../deploys/tests/test_page_fluid.py | 2 +- .../deploys/tests/test_page_sidebar.py | 2 +- .../deploys/tests/test_plotly_app.py | 3 +- .../shiny/shiny-express/dataframe/app.py | 24 ++++++++++++++ .../shiny-express/dataframe/test_dataframe.py | 8 +++++ .../shiny/shiny-express/folium/app.py | 30 ++++++++++++++++++ .../shiny/shiny-express/folium/test_folium.py | 8 +++++ .../render_display/test_render_display.py | 19 ++++++++++++ tests/playwright/utils/express_utils.py | 31 +++++++++++++++++-- 28 files changed, 331 insertions(+), 16 deletions(-) create mode 100644 shiny/api-examples/render_display/app.py create mode 100644 tests/playwright/deploys/apps/shiny-express-accordion/rsconnect-python/shiny-express-accordion.json create mode 100644 tests/playwright/deploys/apps/shiny-express-dataframe/app.py create mode 100644 tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt create mode 100644 tests/playwright/deploys/apps/shiny-express-dataframe/rsconnect-python/shiny-express-dataframe.json create mode 100644 tests/playwright/deploys/apps/shiny-express-folium/app.py create mode 100644 tests/playwright/deploys/apps/shiny-express-folium/requirements.txt create mode 100644 tests/playwright/deploys/apps/shiny-express-folium/rsconnect-python/shiny-express-folium.json create mode 100644 tests/playwright/deploys/apps/shiny-express-page-default/rsconnect-python/shiny-express-page-default.json create mode 100644 tests/playwright/deploys/apps/shiny-express-page-fillable/rsconnect-python/shiny-express-page-fillable.json create mode 100644 tests/playwright/deploys/apps/shiny-express-page-fluid/rsconnect-python/shiny-express-page-fluid.json create mode 100644 tests/playwright/deploys/apps/shiny-express-page-sidebar/rsconnect-python/shiny-express-page-sidebar.json create mode 100644 tests/playwright/deploys/tests/test_dataframe.py create mode 100644 tests/playwright/deploys/tests/test_folium.py create mode 100644 tests/playwright/shiny/shiny-express/dataframe/app.py create mode 100644 tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py create mode 100644 tests/playwright/shiny/shiny-express/folium/app.py create mode 100644 tests/playwright/shiny/shiny-express/folium/test_folium.py create mode 100644 tests/playwright/shiny/shiny-express/render_display/test_render_display.py diff --git a/setup.cfg b/setup.cfg index b39a60d3c..b708ea475 100644 --- a/setup.cfg +++ b/setup.cfg @@ -83,6 +83,7 @@ test = missingno rsconnect-python scikit-learn + folium dev = black>=23.1.0 diff --git a/shiny/api-examples/render_display/app.py b/shiny/api-examples/render_display/app.py new file mode 100644 index 000000000..7bd372616 --- /dev/null +++ b/shiny/api-examples/render_display/app.py @@ -0,0 +1,19 @@ +import datetime + +from shiny import render, ui +from shiny.express import input, layout + +with layout.card(id="card"): + ui.input_slider("val", "slider", 0, 100, 50) + "Text outside of render display call" + ui.tags.br() + f"Rendered time: {str(datetime.datetime.now())}" + + @render.display + def render_display(): + "Text inside of render display call" + ui.tags.br() + "Dynamic slider value: " + input.val() + ui.tags.br() + f"Display's rendered time: {str(datetime.datetime.now())}" diff --git a/tests/playwright/deploys/apps/plotly_app/rsconnect-python/plotly_app.json b/tests/playwright/deploys/apps/plotly_app/rsconnect-python/plotly_app.json index d615e62b2..d651eef8c 100644 --- a/tests/playwright/deploys/apps/plotly_app/rsconnect-python/plotly_app.json +++ b/tests/playwright/deploys/apps/plotly_app/rsconnect-python/plotly_app.json @@ -1,12 +1,11 @@ { - "https://rsc.radixu.com/": { - "server_url": "https://rsc.radixu.com/", - "filename": "/Users/karangathani/Documents/GitHub/py-shiny/tests/playwright/deploys/apps/plotly_app", - "app_url": "https://rsc.radixu.com/content/fc82dde5-c4ba-4748-971b-aacc09613faa/", - "app_id": "fc82dde5-c4ba-4748-971b-aacc09613faa", - "app_guid": "fc82dde5-c4ba-4748-971b-aacc09613faa", + "https://api.shinyapps.io": { + "server_url": "https://api.shinyapps.io", + "app_url": "https://testing-apps.shinyapps.io/example_deploy_app_a1/", + "app_id": 10800241, + "app_guid": null, "title": "example_deploy_app_A", "app_mode": "python-shiny", "app_store_version": 1 } -} \ No newline at end of file +} diff --git a/tests/playwright/deploys/apps/shiny-express-accordion/rsconnect-python/shiny-express-accordion.json b/tests/playwright/deploys/apps/shiny-express-accordion/rsconnect-python/shiny-express-accordion.json new file mode 100644 index 000000000..704a8edb9 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-accordion/rsconnect-python/shiny-express-accordion.json @@ -0,0 +1,11 @@ +{ + "https://api.shinyapps.io": { + "server_url": "https://api.shinyapps.io", + "app_url": "https://testing-apps.shinyapps.io/shiny_express_accordion/", + "app_id": 10800240, + "app_guid": null, + "title": "shiny_express_accordion", + "app_mode": "python-shiny", + "app_store_version": 1 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-dataframe/app.py b/tests/playwright/deploys/apps/shiny-express-dataframe/app.py new file mode 100644 index 000000000..96ea83de1 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-dataframe/app.py @@ -0,0 +1,24 @@ +import pandas as pd + +from shiny import render, ui +from shiny.express import layout + +data = { + "A": [1, 2, 3, 4, 5, 6], + "B": ["a", "b", "c", "d", "e", "f"], + "C": [10.1, 20.2, 30.3, 40.4, 50.5, 60.6], + "D": ["apple", "banana", "cherry", "date", "elderberry", "fig"], + "E": [True, False, True, False, True, False], + "F": ["John", "Jane", "Jim", "Jessie", "Jack", "Jill"], +} + +df = pd.DataFrame(data) + +layout.set_page(layout.page_fillable()) + +with layout.card(id="card"): + ui.h2("Below is a sample dataframe") + + @render.data_frame + def sample_data_frame(id="dataframe"): + return df diff --git a/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt b/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt new file mode 100644 index 000000000..bd8be3f2f --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt @@ -0,0 +1,3 @@ +git+https://github.com/posit-dev/py-shiny.git#egg=shiny +git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools +pandas diff --git a/tests/playwright/deploys/apps/shiny-express-dataframe/rsconnect-python/shiny-express-dataframe.json b/tests/playwright/deploys/apps/shiny-express-dataframe/rsconnect-python/shiny-express-dataframe.json new file mode 100644 index 000000000..951af7d5a --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-dataframe/rsconnect-python/shiny-express-dataframe.json @@ -0,0 +1,11 @@ +{ + "https://api.shinyapps.io": { + "server_url": "https://api.shinyapps.io", + "app_url": "https://testing-apps.shinyapps.io/shiny-express-dataframe/", + "app_id": 10800260, + "app_guid": null, + "title": "shiny-express-dataframe", + "app_mode": "python-shiny", + "app_store_version": 1 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-folium/app.py b/tests/playwright/deploys/apps/shiny-express-folium/app.py new file mode 100644 index 000000000..06d6b42ca --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-folium/app.py @@ -0,0 +1,30 @@ +import folium + +from shiny import render, ui +from shiny.express import input, layout + +locations_coords = { + "San Francisco": (37.79554, -122.39348), + "Los Angeles": (34.05026, -118.25768), + "New York": (40.71222, -74.00490), +} +layout.set_page(layout.page_fixed()) + +with layout.card(id="card"): + "Static Map" + folium.Map( + location=locations_coords["San Francisco"], tiles="USGS.USTopo", zoom_start=12 + ) + ui.input_radio_buttons( + "location", "Location", ["San Francisco", "New York", "Los Angeles"] + ) + + @render.display + def folium_map(): + "Map inside of render display call" + folium.Map( + location=locations_coords[input.location()], + tiles="cartodb positron", + zoom_start=12, + ) + input.location() diff --git a/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt b/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt new file mode 100644 index 000000000..563a4654c --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt @@ -0,0 +1,3 @@ +git+https://github.com/posit-dev/py-shiny.git#egg=shiny +git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools +folium diff --git a/tests/playwright/deploys/apps/shiny-express-folium/rsconnect-python/shiny-express-folium.json b/tests/playwright/deploys/apps/shiny-express-folium/rsconnect-python/shiny-express-folium.json new file mode 100644 index 000000000..af98f5e27 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-folium/rsconnect-python/shiny-express-folium.json @@ -0,0 +1,11 @@ +{ + "https://api.shinyapps.io": { + "server_url": "https://api.shinyapps.io", + "app_url": "https://testing-apps.shinyapps.io/shiny-express-folium/", + "app_id": 10827011, + "app_guid": null, + "title": "shiny-express-folium", + "app_mode": "python-shiny", + "app_store_version": 1 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-page-default/rsconnect-python/shiny-express-page-default.json b/tests/playwright/deploys/apps/shiny-express-page-default/rsconnect-python/shiny-express-page-default.json new file mode 100644 index 000000000..b4cc965be --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-page-default/rsconnect-python/shiny-express-page-default.json @@ -0,0 +1,11 @@ +{ + "https://api.shinyapps.io": { + "server_url": "https://api.shinyapps.io", + "app_url": "https://testing-apps.shinyapps.io/shiny_express_page_default/", + "app_id": 10800233, + "app_guid": null, + "title": "shiny_express_page_default", + "app_mode": "python-shiny", + "app_store_version": 1 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-page-fillable/rsconnect-python/shiny-express-page-fillable.json b/tests/playwright/deploys/apps/shiny-express-page-fillable/rsconnect-python/shiny-express-page-fillable.json new file mode 100644 index 000000000..23e73f9d6 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-page-fillable/rsconnect-python/shiny-express-page-fillable.json @@ -0,0 +1,11 @@ +{ + "https://api.shinyapps.io": { + "server_url": "https://api.shinyapps.io", + "app_url": "https://testing-apps.shinyapps.io/express_page_fillable/", + "app_id": 10800242, + "app_guid": null, + "title": "express_page_fillable", + "app_mode": "python-shiny", + "app_store_version": 1 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-page-fluid/rsconnect-python/shiny-express-page-fluid.json b/tests/playwright/deploys/apps/shiny-express-page-fluid/rsconnect-python/shiny-express-page-fluid.json new file mode 100644 index 000000000..65e7b6352 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-page-fluid/rsconnect-python/shiny-express-page-fluid.json @@ -0,0 +1,11 @@ +{ + "https://api.shinyapps.io": { + "server_url": "https://api.shinyapps.io", + "app_url": "https://testing-apps.shinyapps.io/express_page_fluid/", + "app_id": 10800235, + "app_guid": null, + "title": "express_page_fluid", + "app_mode": "python-shiny", + "app_store_version": 1 + } +} diff --git a/tests/playwright/deploys/apps/shiny-express-page-sidebar/rsconnect-python/shiny-express-page-sidebar.json b/tests/playwright/deploys/apps/shiny-express-page-sidebar/rsconnect-python/shiny-express-page-sidebar.json new file mode 100644 index 000000000..4087ebd04 --- /dev/null +++ b/tests/playwright/deploys/apps/shiny-express-page-sidebar/rsconnect-python/shiny-express-page-sidebar.json @@ -0,0 +1,11 @@ +{ + "https://api.shinyapps.io": { + "server_url": "https://api.shinyapps.io", + "app_url": "https://testing-apps.shinyapps.io/express_page_sidebar/", + "app_id": 10800234, + "app_guid": null, + "title": "express_page_sidebar", + "app_mode": "python-shiny", + "app_store_version": 1 + } +} diff --git a/tests/playwright/deploys/tests/test_accordion.py b/tests/playwright/deploys/tests/test_accordion.py index e127e14c1..cf4c7a689 100644 --- a/tests/playwright/deploys/tests/test_accordion.py +++ b/tests/playwright/deploys/tests/test_accordion.py @@ -15,7 +15,7 @@ @pytest.mark.integrationtest @pytest.mark.only_browser("chromium") -@pytest.mark.parametrize("location", ["connect"]) +@pytest.mark.parametrize("location", ["connect", "shinyapps"]) def test_express_accordion(page: Page, location: str) -> None: page_url = deploy(location, APP_NAME, app_file_path) page.goto(page_url, timeout=PAGE_TIMEOUT) diff --git a/tests/playwright/deploys/tests/test_dataframe.py b/tests/playwright/deploys/tests/test_dataframe.py new file mode 100644 index 000000000..eccd8d4b1 --- /dev/null +++ b/tests/playwright/deploys/tests/test_dataframe.py @@ -0,0 +1,22 @@ +import os + +import pytest +from playwright.sync_api import Page +from utils.deploy_utils import deploy +from utils.express_utils import verify_express_dataframe + +APP_DIR = "shiny-express-dataframe" +APP_NAME = "shiny-express-dataframe" +PAGE_TIMEOUT = 120 * 1000 +EXPECT_TIMEOUT = 30 * 1000 +current_dir = os.path.dirname(os.path.abspath(__file__)) +app_file_path = os.path.join(os.path.dirname(current_dir), "apps", APP_DIR) + + +@pytest.mark.integrationtest +@pytest.mark.only_browser("chromium") +@pytest.mark.parametrize("location", ["connect", "shinyapps"]) +def test_express_dataframe(page: Page, location: str) -> None: + page_url = deploy(location, APP_NAME, app_file_path) + page.goto(page_url, timeout=PAGE_TIMEOUT) + verify_express_dataframe(page) diff --git a/tests/playwright/deploys/tests/test_folium.py b/tests/playwright/deploys/tests/test_folium.py new file mode 100644 index 000000000..4b25565c2 --- /dev/null +++ b/tests/playwright/deploys/tests/test_folium.py @@ -0,0 +1,22 @@ +import os + +import pytest +from playwright.sync_api import Page +from utils.deploy_utils import deploy +from utils.express_utils import verify_express_folium_render + +APP_DIR = "shiny-express-folium" +APP_NAME = "shiny-express-folium" +PAGE_TIMEOUT = 120 * 1000 +EXPECT_TIMEOUT = 30 * 1000 +current_dir = os.path.dirname(os.path.abspath(__file__)) +app_file_path = os.path.join(os.path.dirname(current_dir), "apps", APP_DIR) + + +@pytest.mark.integrationtest +@pytest.mark.only_browser("chromium") +@pytest.mark.parametrize("location", ["connect", "shinyapps"]) +def test_folium_map(page: Page, location: str) -> None: + page_url = deploy(location, APP_NAME, app_file_path) + page.goto(page_url, timeout=PAGE_TIMEOUT) + verify_express_folium_render(page) diff --git a/tests/playwright/deploys/tests/test_page_default.py b/tests/playwright/deploys/tests/test_page_default.py index f08731d3d..20beae0c4 100644 --- a/tests/playwright/deploys/tests/test_page_default.py +++ b/tests/playwright/deploys/tests/test_page_default.py @@ -18,7 +18,7 @@ @pytest.mark.integrationtest @pytest.mark.only_browser("chromium") -@pytest.mark.parametrize("location", ["connect"]) +@pytest.mark.parametrize("location", ["connect", "shinyapps"]) def test_express_page_default(page: Page, location: str) -> None: page_url = deploy(location, APP_NAME, app_file_path) page.goto(page_url, timeout=PAGE_TIMEOUT) diff --git a/tests/playwright/deploys/tests/test_page_fillable.py b/tests/playwright/deploys/tests/test_page_fillable.py index 4849a954c..a87b9fa85 100644 --- a/tests/playwright/deploys/tests/test_page_fillable.py +++ b/tests/playwright/deploys/tests/test_page_fillable.py @@ -18,7 +18,7 @@ @pytest.mark.integrationtest @pytest.mark.only_browser("chromium") -@pytest.mark.parametrize("location", ["connect"]) +@pytest.mark.parametrize("location", ["connect", "shinyapps"]) def test_express_page_fillable(page: Page, location: str) -> None: page_url = deploy(location, APP_NAME, app_file_path) page.goto(page_url, timeout=PAGE_TIMEOUT) diff --git a/tests/playwright/deploys/tests/test_page_fluid.py b/tests/playwright/deploys/tests/test_page_fluid.py index e108e4031..8f0cb1a96 100644 --- a/tests/playwright/deploys/tests/test_page_fluid.py +++ b/tests/playwright/deploys/tests/test_page_fluid.py @@ -18,7 +18,7 @@ @pytest.mark.integrationtest @pytest.mark.only_browser("chromium") -@pytest.mark.parametrize("location", ["connect"]) +@pytest.mark.parametrize("location", ["connect", "shinyapps"]) def test_express_page_fluid(page: Page, location: str) -> None: page_url = deploy(location, APP_NAME, app_file_path) page.goto(page_url, timeout=PAGE_TIMEOUT) diff --git a/tests/playwright/deploys/tests/test_page_sidebar.py b/tests/playwright/deploys/tests/test_page_sidebar.py index c22ecb6dd..b8a967bbf 100644 --- a/tests/playwright/deploys/tests/test_page_sidebar.py +++ b/tests/playwright/deploys/tests/test_page_sidebar.py @@ -18,7 +18,7 @@ @pytest.mark.integrationtest @pytest.mark.only_browser("chromium") -@pytest.mark.parametrize("location", ["connect"]) +@pytest.mark.parametrize("location", ["connect", "shinyapps"]) def test_express_page_sidebar(page: Page, location: str) -> None: page_url = deploy(location, APP_NAME, app_file_path) page.goto(page_url, timeout=PAGE_TIMEOUT) diff --git a/tests/playwright/deploys/tests/test_plotly_app.py b/tests/playwright/deploys/tests/test_plotly_app.py index 64df05ef9..fc242701d 100644 --- a/tests/playwright/deploys/tests/test_plotly_app.py +++ b/tests/playwright/deploys/tests/test_plotly_app.py @@ -18,8 +18,7 @@ @pytest.mark.integrationtest @pytest.mark.only_browser("chromium") -@pytest.mark.parametrize("location", ["connect"]) -# TODO-karan: Add shinyapps.io support once it is stable +@pytest.mark.parametrize("location", ["connect", "shinyapps"]) def test_deploys(page: Page, location: str) -> None: page_url = deploy(location, APP_NAME, app_file_path) page.goto(page_url, timeout=PAGE_TIMEOUT) diff --git a/tests/playwright/shiny/shiny-express/dataframe/app.py b/tests/playwright/shiny/shiny-express/dataframe/app.py new file mode 100644 index 000000000..4dfb6044b --- /dev/null +++ b/tests/playwright/shiny/shiny-express/dataframe/app.py @@ -0,0 +1,24 @@ +import pandas as pd + +from shiny import render, ui +from shiny.express import layout + +data = { + "A": [1, 2, 3, 4, 5, 6], + "B": ["a", "b", "c", "d", "e", "f"], + "C": [10.1, 20.2, 30.3, 40.4, 50.5, 60.6], + "D": ["apple", "banana", "cherry", "date", "elderberry", "fig"], + "E": [True, False, True, False, True, False], + "F": ["John", "Jane", "Jim", "Jessie", "Jack", "Jill"], +} + +df = pd.DataFrame(data) + +layout.set_page(layout.page_fillable()) + +with layout.card(id="card"): + ui.h2("Below is a sample dataframe") + + @render.data_frame + def sample_data_frame(id: str = "dataframe"): + return df diff --git a/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py b/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py new file mode 100644 index 000000000..05a53c4ae --- /dev/null +++ b/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py @@ -0,0 +1,8 @@ +from conftest import ShinyAppProc +from playwright.sync_api import Page +from utils.express_utils import verify_express_dataframe + + +def test_page_default(page: Page, local_app: ShinyAppProc) -> None: + page.goto(local_app.url) + verify_express_dataframe(page) diff --git a/tests/playwright/shiny/shiny-express/folium/app.py b/tests/playwright/shiny/shiny-express/folium/app.py new file mode 100644 index 000000000..06d6b42ca --- /dev/null +++ b/tests/playwright/shiny/shiny-express/folium/app.py @@ -0,0 +1,30 @@ +import folium + +from shiny import render, ui +from shiny.express import input, layout + +locations_coords = { + "San Francisco": (37.79554, -122.39348), + "Los Angeles": (34.05026, -118.25768), + "New York": (40.71222, -74.00490), +} +layout.set_page(layout.page_fixed()) + +with layout.card(id="card"): + "Static Map" + folium.Map( + location=locations_coords["San Francisco"], tiles="USGS.USTopo", zoom_start=12 + ) + ui.input_radio_buttons( + "location", "Location", ["San Francisco", "New York", "Los Angeles"] + ) + + @render.display + def folium_map(): + "Map inside of render display call" + folium.Map( + location=locations_coords[input.location()], + tiles="cartodb positron", + zoom_start=12, + ) + input.location() diff --git a/tests/playwright/shiny/shiny-express/folium/test_folium.py b/tests/playwright/shiny/shiny-express/folium/test_folium.py new file mode 100644 index 000000000..bb126e7ab --- /dev/null +++ b/tests/playwright/shiny/shiny-express/folium/test_folium.py @@ -0,0 +1,8 @@ +from conftest import ShinyAppProc +from playwright.sync_api import Page +from utils.express_utils import verify_express_folium_render + + +def test_folium_map(page: Page, local_app: ShinyAppProc) -> None: + page.goto(local_app.url) + verify_express_folium_render(page) diff --git a/tests/playwright/shiny/shiny-express/render_display/test_render_display.py b/tests/playwright/shiny/shiny-express/render_display/test_render_display.py new file mode 100644 index 000000000..d097556f4 --- /dev/null +++ b/tests/playwright/shiny/shiny-express/render_display/test_render_display.py @@ -0,0 +1,19 @@ +from conftest import ShinyAppProc, create_doc_example_fixture +from playwright.sync_api import Page, expect + +app = create_doc_example_fixture("render_display") + +EXPECT_TIMEOUT = 30 * 1000 + + +def test_render_display(page: Page, app: ShinyAppProc) -> None: + page.goto(app.url) + expect(page.get_by_text("Text outside of render display call")).to_have_count( + 1, timeout=EXPECT_TIMEOUT + ) + expect(page.get_by_text("Text inside of render display call")).to_have_count( + 1, timeout=EXPECT_TIMEOUT + ) + expect(page.get_by_text("Dynamic slider value: 50")).to_have_count( + 1, timeout=EXPECT_TIMEOUT + ) diff --git a/tests/playwright/utils/express_utils.py b/tests/playwright/utils/express_utils.py index 961500efa..4967a64ef 100644 --- a/tests/playwright/utils/express_utils.py +++ b/tests/playwright/utils/express_utils.py @@ -2,8 +2,15 @@ import typing -from controls import Accordion, Card, LayoutNavsetTab, OutputTextVerbatim, Sidebar -from playwright.sync_api import Page +from controls import ( + Accordion, + Card, + LayoutNavsetTab, + OutputDataFrame, + OutputTextVerbatim, + Sidebar, +) +from playwright.sync_api import Page, expect from shiny import ui from shiny.express import layout @@ -83,3 +90,23 @@ def verify_express_page_sidebar(page: Page) -> None: output_txt = OutputTextVerbatim(page, "txt") output_txt.expect_value("50") compare_annotations(ui.sidebar, layout.sidebar) + + +def verify_express_dataframe(page: Page) -> None: + dataframe = OutputDataFrame(page, "sample_data_frame") + dataframe.expect_n_row(6) + + +def verify_express_folium_render(page: Page) -> None: + expect(page.get_by_text("Static Map")).to_have_count(1) + expect(page.get_by_text("Map inside of render display call")).to_have_count(1) + # map inside the @render.display + expect( + page.frame_locator("iframe").nth(1).get_by_role("link", name="OpenStreetMap") + ).to_have_count(1) + # map outside of the @render.display at the top level + expect( + page.frame_locator("iframe") + .nth(0) + .get_by_role("link", name="U.S. Geological Survey") + ).to_have_count(1) From d7c51a35cb981f7a2b480398de7005c61961b226 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Tue, 19 Dec 2023 11:33:18 -0800 Subject: [PATCH 2/5] ignore pyright warning --- tests/playwright/shiny/shiny-express/folium/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/playwright/shiny/shiny-express/folium/app.py b/tests/playwright/shiny/shiny-express/folium/app.py index 06d6b42ca..f22d430d5 100644 --- a/tests/playwright/shiny/shiny-express/folium/app.py +++ b/tests/playwright/shiny/shiny-express/folium/app.py @@ -1,4 +1,4 @@ -import folium +import folium # pyright: ignore[reportMissingTypeStubs] from shiny import render, ui from shiny.express import input, layout From 0215b78cfa92d762d8e53148db6a08bb439066ec Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Tue, 19 Dec 2023 11:38:08 -0800 Subject: [PATCH 3/5] allow shiny express apps in api-examples --- tests/playwright/examples/test_examples.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/playwright/examples/test_examples.py b/tests/playwright/examples/test_examples.py index 95b8ff02a..3d54bdbba 100644 --- a/tests/playwright/examples/test_examples.py +++ b/tests/playwright/examples/test_examples.py @@ -52,6 +52,8 @@ def get_apps(path: str) -> typing.List[str]: ], } app_allow_external_errors: typing.List[str] = [ + # if shiny express app detected + "Detected Shiny Express app", # plotnine: https://github.com/has2k1/plotnine/issues/713 # mizani: https://github.com/has2k1/mizani/issues/34 # seaborn: https://github.com/mwaskom/seaborn/issues/3457 From b1e329cb7107abbd146326b5ac4fc924a0b45297 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Sun, 31 Dec 2023 12:26:39 -0800 Subject: [PATCH 4/5] Update deploy apps to new shiny express code --- .../deploys/apps/shiny-express-dataframe/app.py | 10 +++++----- .../deploys/apps/shiny-express-folium/app.py | 10 +++++----- .../deploys/apps/shiny-express-page-fillable/app.py | 2 +- .../deploys/apps/shiny-express-page-fluid/app.py | 2 +- .../deploys/apps/shiny-express-page-sidebar/app.py | 2 +- tests/playwright/shiny/shiny-express/dataframe/app.py | 8 ++++---- tests/playwright/shiny/shiny-express/folium/app.py | 8 ++++---- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/playwright/deploys/apps/shiny-express-dataframe/app.py b/tests/playwright/deploys/apps/shiny-express-dataframe/app.py index 96ea83de1..5902c0a78 100644 --- a/tests/playwright/deploys/apps/shiny-express-dataframe/app.py +++ b/tests/playwright/deploys/apps/shiny-express-dataframe/app.py @@ -1,7 +1,7 @@ import pandas as pd -from shiny import render, ui -from shiny.express import layout +from shiny import render +from shiny.express import ui data = { "A": [1, 2, 3, 4, 5, 6], @@ -14,11 +14,11 @@ df = pd.DataFrame(data) -layout.set_page(layout.page_fillable()) +ui.page_opts(fillable=True) -with layout.card(id="card"): +with ui.card(id="card"): ui.h2("Below is a sample dataframe") @render.data_frame - def sample_data_frame(id="dataframe"): + def sample_data_frame(id: str = "dataframe"): return df diff --git a/tests/playwright/deploys/apps/shiny-express-folium/app.py b/tests/playwright/deploys/apps/shiny-express-folium/app.py index 06d6b42ca..15dac58e2 100644 --- a/tests/playwright/deploys/apps/shiny-express-folium/app.py +++ b/tests/playwright/deploys/apps/shiny-express-folium/app.py @@ -1,16 +1,16 @@ -import folium +import folium # pyright: ignore[reportMissingTypeStubs] -from shiny import render, ui -from shiny.express import input, layout +from shiny import render +from shiny.express import input, ui locations_coords = { "San Francisco": (37.79554, -122.39348), "Los Angeles": (34.05026, -118.25768), "New York": (40.71222, -74.00490), } -layout.set_page(layout.page_fixed()) +ui.page_opts(full_width=False) -with layout.card(id="card"): +with ui.card(id="card"): "Static Map" folium.Map( location=locations_coords["San Francisco"], tiles="USGS.USTopo", zoom_start=12 diff --git a/tests/playwright/deploys/apps/shiny-express-page-fillable/app.py b/tests/playwright/deploys/apps/shiny-express-page-fillable/app.py index 9c2013b04..94e8b2a99 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-fillable/app.py +++ b/tests/playwright/deploys/apps/shiny-express-page-fillable/app.py @@ -1,7 +1,7 @@ from shiny import render from shiny.express import input, ui -ui.set_page(ui.page_fillable()) +ui.page_opts(fillable=True) with ui.card(id="card"): ui.input_slider("a", "A", 1, 100, 50) diff --git a/tests/playwright/deploys/apps/shiny-express-page-fluid/app.py b/tests/playwright/deploys/apps/shiny-express-page-fluid/app.py index 0422113b8..54fd50c64 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-fluid/app.py +++ b/tests/playwright/deploys/apps/shiny-express-page-fluid/app.py @@ -1,7 +1,7 @@ from shiny import render from shiny.express import input, ui -ui.set_page(ui.page_fluid()) +ui.page_opts(full_width=True) with ui.card(id="card"): ui.input_slider("a", "A", 1, 100, 50) diff --git a/tests/playwright/deploys/apps/shiny-express-page-sidebar/app.py b/tests/playwright/deploys/apps/shiny-express-page-sidebar/app.py index fac04a612..8168abf73 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-sidebar/app.py +++ b/tests/playwright/deploys/apps/shiny-express-page-sidebar/app.py @@ -1,7 +1,7 @@ from shiny import render from shiny.express import input, ui -ui.set_page(ui.page_sidebar(title="PageTitle")) +ui.page_opts(title="PageTitle") with ui.sidebar(id="sidebar", title="SidebarTitle"): "Sidebar Content" diff --git a/tests/playwright/shiny/shiny-express/dataframe/app.py b/tests/playwright/shiny/shiny-express/dataframe/app.py index 4dfb6044b..5902c0a78 100644 --- a/tests/playwright/shiny/shiny-express/dataframe/app.py +++ b/tests/playwright/shiny/shiny-express/dataframe/app.py @@ -1,7 +1,7 @@ import pandas as pd -from shiny import render, ui -from shiny.express import layout +from shiny import render +from shiny.express import ui data = { "A": [1, 2, 3, 4, 5, 6], @@ -14,9 +14,9 @@ df = pd.DataFrame(data) -layout.set_page(layout.page_fillable()) +ui.page_opts(fillable=True) -with layout.card(id="card"): +with ui.card(id="card"): ui.h2("Below is a sample dataframe") @render.data_frame diff --git a/tests/playwright/shiny/shiny-express/folium/app.py b/tests/playwright/shiny/shiny-express/folium/app.py index f22d430d5..15dac58e2 100644 --- a/tests/playwright/shiny/shiny-express/folium/app.py +++ b/tests/playwright/shiny/shiny-express/folium/app.py @@ -1,16 +1,16 @@ import folium # pyright: ignore[reportMissingTypeStubs] -from shiny import render, ui -from shiny.express import input, layout +from shiny import render +from shiny.express import input, ui locations_coords = { "San Francisco": (37.79554, -122.39348), "Los Angeles": (34.05026, -118.25768), "New York": (40.71222, -74.00490), } -layout.set_page(layout.page_fixed()) +ui.page_opts(full_width=False) -with layout.card(id="card"): +with ui.card(id="card"): "Static Map" folium.Map( location=locations_coords["San Francisco"], tiles="USGS.USTopo", zoom_start=12 From 4c17a971df6494eaf9804aa3c3dfc518b22a15ce Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Wed, 3 Jan 2024 22:32:45 -0800 Subject: [PATCH 5/5] Change the py-shiny line to remove .git#egg=shiny --- .../deploys/apps/shiny-express-accordion/requirements.txt | 2 +- .../deploys/apps/shiny-express-dataframe/requirements.txt | 2 +- .../deploys/apps/shiny-express-folium/requirements.txt | 2 +- .../deploys/apps/shiny-express-page-default/requirements.txt | 2 +- .../deploys/apps/shiny-express-page-fillable/requirements.txt | 2 +- .../deploys/apps/shiny-express-page-fluid/requirements.txt | 2 +- .../deploys/apps/shiny-express-page-sidebar/requirements.txt | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/playwright/deploys/apps/shiny-express-accordion/requirements.txt b/tests/playwright/deploys/apps/shiny-express-accordion/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-accordion/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-accordion/requirements.txt @@ -1,2 +1,2 @@ -git+https://github.com/posit-dev/py-shiny.git#egg=shiny +git+https://github.com/posit-dev/py-shiny git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools diff --git a/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt b/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt index bd8be3f2f..c87d9ef1b 100644 --- a/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-dataframe/requirements.txt @@ -1,3 +1,3 @@ -git+https://github.com/posit-dev/py-shiny.git#egg=shiny +git+https://github.com/posit-dev/py-shiny git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools pandas diff --git a/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt b/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt index 563a4654c..d7dad04f9 100644 --- a/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-folium/requirements.txt @@ -1,3 +1,3 @@ -git+https://github.com/posit-dev/py-shiny.git#egg=shiny +git+https://github.com/posit-dev/py-shiny git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools folium diff --git a/tests/playwright/deploys/apps/shiny-express-page-default/requirements.txt b/tests/playwright/deploys/apps/shiny-express-page-default/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-default/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-page-default/requirements.txt @@ -1,2 +1,2 @@ -git+https://github.com/posit-dev/py-shiny.git#egg=shiny +git+https://github.com/posit-dev/py-shiny git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools diff --git a/tests/playwright/deploys/apps/shiny-express-page-fillable/requirements.txt b/tests/playwright/deploys/apps/shiny-express-page-fillable/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-fillable/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-page-fillable/requirements.txt @@ -1,2 +1,2 @@ -git+https://github.com/posit-dev/py-shiny.git#egg=shiny +git+https://github.com/posit-dev/py-shiny git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools diff --git a/tests/playwright/deploys/apps/shiny-express-page-fluid/requirements.txt b/tests/playwright/deploys/apps/shiny-express-page-fluid/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-fluid/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-page-fluid/requirements.txt @@ -1,2 +1,2 @@ -git+https://github.com/posit-dev/py-shiny.git#egg=shiny +git+https://github.com/posit-dev/py-shiny git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools diff --git a/tests/playwright/deploys/apps/shiny-express-page-sidebar/requirements.txt b/tests/playwright/deploys/apps/shiny-express-page-sidebar/requirements.txt index eea677e43..066ce0faf 100644 --- a/tests/playwright/deploys/apps/shiny-express-page-sidebar/requirements.txt +++ b/tests/playwright/deploys/apps/shiny-express-page-sidebar/requirements.txt @@ -1,2 +1,2 @@ -git+https://github.com/posit-dev/py-shiny.git#egg=shiny +git+https://github.com/posit-dev/py-shiny git+https://github.com/posit-dev/py-htmltools.git#egg=htmltools