-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port exercises 305 and 306 to shiny express
- Loading branch information
Showing
27 changed files
with
234 additions
and
134 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.quarto/_freeze/docs/exercises/express-305-dynamic-ui/index/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
.quarto/_freeze/docs/exercises/express-306-navset/index/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"title":"503 Extract function","markdown":{"yaml":{"title":"503 Extract function"},"headingText":"| echo: false","containsRefs":false,"markdown":"\n\n```{python}\n# | output: asis\nimport sys\nhelpers_path = \"../\"\nif helpers_path not in sys.path:\n sys.path.append(helpers_path)\nfrom helpers import problem_tabs_express, getcwd\n\nproblem_tabs_express(getcwd())\n```\n","srcMarkdownNoYaml":"\n\n```{python}\n# | echo: false\n# | output: asis\nimport sys\nhelpers_path = \"../\"\nif helpers_path not in sys.path:\n sys.path.append(helpers_path)\nfrom helpers import problem_tabs_express, getcwd\n\nproblem_tabs_express(getcwd())\n```\n"},"formats":{"html":{"identifier":{"display-name":"HTML","target-format":"html","base-format":"html"},"execute":{"fig-width":7,"fig-height":5,"fig-format":"retina","fig-dpi":96,"df-print":"default","error":false,"eval":true,"cache":null,"freeze":"auto","echo":true,"output":true,"warning":true,"include":true,"keep-md":false,"keep-ipynb":false,"ipynb":null,"enabled":null,"daemon":null,"daemon-restart":false,"debug":false,"ipynb-filters":[],"ipynb-shell-interactivity":null,"plotly-connected":true,"engine":"jupyter"},"render":{"keep-tex":false,"keep-typ":false,"keep-source":false,"keep-hidden":false,"prefer-html":false,"output-divs":true,"output-ext":"html","fig-align":"default","fig-pos":null,"fig-env":null,"code-fold":"none","code-overflow":"scroll","code-link":false,"code-line-numbers":false,"code-tools":false,"tbl-colwidths":"auto","merge-includes":true,"inline-includes":false,"preserve-yaml":false,"latex-auto-mk":true,"latex-auto-install":true,"latex-clean":true,"latex-min-runs":1,"latex-max-runs":10,"latex-makeindex":"makeindex","latex-makeindex-opts":[],"latex-tlmgr-opts":[],"latex-input-paths":[],"latex-output-dir":null,"link-external-icon":false,"link-external-newwindow":false,"self-contained-math":false,"format-resources":[],"notebook-links":true},"pandoc":{"standalone":true,"wrap":"none","default-image-extension":"png","to":"html","filters":["shinylive"],"css":["../../../styles.css"],"toc":true,"output-file":"index.html"},"language":{"toc-title-document":"Table of contents","toc-title-website":"On this page","related-formats-title":"Other Formats","related-notebooks-title":"Notebooks","source-notebooks-prefix":"Source","other-links-title":"Other Links","code-links-title":"Code Links","launch-dev-container-title":"Launch Dev Container","launch-binder-title":"Launch Binder","article-notebook-label":"Article Notebook","notebook-preview-download":"Download Notebook","notebook-preview-download-src":"Download Source","notebook-preview-back":"Back to Article","manuscript-meca-bundle":"MECA Bundle","section-title-abstract":"Abstract","section-title-appendices":"Appendices","section-title-footnotes":"Footnotes","section-title-references":"References","section-title-reuse":"Reuse","section-title-copyright":"Copyright","section-title-citation":"Citation","appendix-attribution-cite-as":"For attribution, please cite this work as:","appendix-attribution-bibtex":"BibTeX citation:","appendix-view-license":"View License","title-block-author-single":"Author","title-block-author-plural":"Authors","title-block-affiliation-single":"Affiliation","title-block-affiliation-plural":"Affiliations","title-block-published":"Published","title-block-modified":"Modified","title-block-keywords":"Keywords","callout-tip-title":"Tip","callout-note-title":"Note","callout-warning-title":"Warning","callout-important-title":"Important","callout-caution-title":"Caution","code-summary":"Code","code-tools-menu-caption":"Code","code-tools-show-all-code":"Show All Code","code-tools-hide-all-code":"Hide All Code","code-tools-view-source":"View Source","code-tools-source-code":"Source Code","tools-share":"Share","tools-download":"Download","code-line":"Line","code-lines":"Lines","copy-button-tooltip":"Copy to Clipboard","copy-button-tooltip-success":"Copied!","repo-action-links-edit":"Edit this page","repo-action-links-source":"View source","repo-action-links-issue":"Report an issue","back-to-top":"Back to top","search-no-results-text":"No results","search-matching-documents-text":"matching documents","search-copy-link-title":"Copy link to search","search-hide-matches-text":"Hide additional matches","search-more-match-text":"more match in this document","search-more-matches-text":"more matches in this document","search-clear-button-title":"Clear","search-text-placeholder":"","search-detached-cancel-button-title":"Cancel","search-submit-button-title":"Submit","search-label":"Search","toggle-section":"Toggle section","toggle-sidebar":"Toggle sidebar navigation","toggle-dark-mode":"Toggle dark mode","toggle-reader-mode":"Toggle reader mode","toggle-navigation":"Toggle navigation","crossref-fig-title":"Figure","crossref-tbl-title":"Table","crossref-lst-title":"Listing","crossref-thm-title":"Theorem","crossref-lem-title":"Lemma","crossref-cor-title":"Corollary","crossref-prp-title":"Proposition","crossref-cnj-title":"Conjecture","crossref-def-title":"Definition","crossref-exm-title":"Example","crossref-exr-title":"Exercise","crossref-ch-prefix":"Chapter","crossref-apx-prefix":"Appendix","crossref-sec-prefix":"Section","crossref-eq-prefix":"Equation","crossref-lof-title":"List of Figures","crossref-lot-title":"List of Tables","crossref-lol-title":"List of Listings","environment-proof-title":"Proof","environment-remark-title":"Remark","environment-solution-title":"Solution","listing-page-order-by":"Order By","listing-page-order-by-default":"Default","listing-page-order-by-date-asc":"Oldest","listing-page-order-by-date-desc":"Newest","listing-page-order-by-number-desc":"High to Low","listing-page-order-by-number-asc":"Low to High","listing-page-field-date":"Date","listing-page-field-title":"Title","listing-page-field-description":"Description","listing-page-field-author":"Author","listing-page-field-filename":"File Name","listing-page-field-filemodified":"Modified","listing-page-field-subtitle":"Subtitle","listing-page-field-readingtime":"Reading Time","listing-page-field-wordcount":"Word Count","listing-page-field-categories":"Categories","listing-page-minutes-compact":"{0} min","listing-page-category-all":"All","listing-page-no-matches":"No matching items","listing-page-words":"{0} words","listing-page-filter":"Filter","draft":"Draft"},"metadata":{"lang":"en","fig-responsive":true,"quarto-version":"1.5.55","theme":"materia","title":"503 Extract function"},"extensions":{"book":{"multiFile":true}}}},"projectFormats":["html"]} | ||
{"title":"503 Extract function","markdown":{"yaml":{"title":"306 Extract function"},"headingText":"| echo: false","containsRefs":false,"markdown":"\n\n```{python}\n# | output: asis\nimport sys\nhelpers_path = \"../\"\nif helpers_path not in sys.path:\n sys.path.append(helpers_path)\nfrom helpers import problem_tabs_express, getcwd\n\nproblem_tabs_express(getcwd())\n```\n","srcMarkdownNoYaml":"\n\n```{python}\n# | echo: false\n# | output: asis\nimport sys\nhelpers_path = \"../\"\nif helpers_path not in sys.path:\n sys.path.append(helpers_path)\nfrom helpers import problem_tabs_express, getcwd\n\nproblem_tabs_express(getcwd())\n```\n"},"formats":{"html":{"identifier":{"display-name":"HTML","target-format":"html","base-format":"html"},"execute":{"fig-width":7,"fig-height":5,"fig-format":"retina","fig-dpi":96,"df-print":"default","error":false,"eval":true,"cache":null,"freeze":"auto","echo":true,"output":true,"warning":true,"include":true,"keep-md":false,"keep-ipynb":false,"ipynb":null,"enabled":null,"daemon":null,"daemon-restart":false,"debug":false,"ipynb-filters":[],"ipynb-shell-interactivity":null,"plotly-connected":true,"engine":"jupyter"},"render":{"keep-tex":false,"keep-typ":false,"keep-source":false,"keep-hidden":false,"prefer-html":false,"output-divs":true,"output-ext":"html","fig-align":"default","fig-pos":null,"fig-env":null,"code-fold":"none","code-overflow":"scroll","code-link":false,"code-line-numbers":false,"code-tools":false,"tbl-colwidths":"auto","merge-includes":true,"inline-includes":false,"preserve-yaml":false,"latex-auto-mk":true,"latex-auto-install":true,"latex-clean":true,"latex-min-runs":1,"latex-max-runs":10,"latex-makeindex":"makeindex","latex-makeindex-opts":[],"latex-tlmgr-opts":[],"latex-input-paths":[],"latex-output-dir":null,"link-external-icon":false,"link-external-newwindow":false,"self-contained-math":false,"format-resources":[],"notebook-links":true},"pandoc":{"standalone":true,"wrap":"none","default-image-extension":"png","to":"html","filters":["shinylive"],"css":["../../../styles.css"],"toc":true,"output-file":"index.html"},"language":{"toc-title-document":"Table of contents","toc-title-website":"On this page","related-formats-title":"Other Formats","related-notebooks-title":"Notebooks","source-notebooks-prefix":"Source","other-links-title":"Other Links","code-links-title":"Code Links","launch-dev-container-title":"Launch Dev Container","launch-binder-title":"Launch Binder","article-notebook-label":"Article Notebook","notebook-preview-download":"Download Notebook","notebook-preview-download-src":"Download Source","notebook-preview-back":"Back to Article","manuscript-meca-bundle":"MECA Bundle","section-title-abstract":"Abstract","section-title-appendices":"Appendices","section-title-footnotes":"Footnotes","section-title-references":"References","section-title-reuse":"Reuse","section-title-copyright":"Copyright","section-title-citation":"Citation","appendix-attribution-cite-as":"For attribution, please cite this work as:","appendix-attribution-bibtex":"BibTeX citation:","appendix-view-license":"View License","title-block-author-single":"Author","title-block-author-plural":"Authors","title-block-affiliation-single":"Affiliation","title-block-affiliation-plural":"Affiliations","title-block-published":"Published","title-block-modified":"Modified","title-block-keywords":"Keywords","callout-tip-title":"Tip","callout-note-title":"Note","callout-warning-title":"Warning","callout-important-title":"Important","callout-caution-title":"Caution","code-summary":"Code","code-tools-menu-caption":"Code","code-tools-show-all-code":"Show All Code","code-tools-hide-all-code":"Hide All Code","code-tools-view-source":"View Source","code-tools-source-code":"Source Code","tools-share":"Share","tools-download":"Download","code-line":"Line","code-lines":"Lines","copy-button-tooltip":"Copy to Clipboard","copy-button-tooltip-success":"Copied!","repo-action-links-edit":"Edit this page","repo-action-links-source":"View source","repo-action-links-issue":"Report an issue","back-to-top":"Back to top","search-no-results-text":"No results","search-matching-documents-text":"matching documents","search-copy-link-title":"Copy link to search","search-hide-matches-text":"Hide additional matches","search-more-match-text":"more match in this document","search-more-matches-text":"more matches in this document","search-clear-button-title":"Clear","search-text-placeholder":"","search-detached-cancel-button-title":"Cancel","search-submit-button-title":"Submit","search-label":"Search","toggle-section":"Toggle section","toggle-sidebar":"Toggle sidebar navigation","toggle-dark-mode":"Toggle dark mode","toggle-reader-mode":"Toggle reader mode","toggle-navigation":"Toggle navigation","crossref-fig-title":"Figure","crossref-tbl-title":"Table","crossref-lst-title":"Listing","crossref-thm-title":"Theorem","crossref-lem-title":"Lemma","crossref-cor-title":"Corollary","crossref-prp-title":"Proposition","crossref-cnj-title":"Conjecture","crossref-def-title":"Definition","crossref-exm-title":"Example","crossref-exr-title":"Exercise","crossref-ch-prefix":"Chapter","crossref-apx-prefix":"Appendix","crossref-sec-prefix":"Section","crossref-eq-prefix":"Equation","crossref-lof-title":"List of Figures","crossref-lot-title":"List of Tables","crossref-lol-title":"List of Listings","environment-proof-title":"Proof","environment-remark-title":"Remark","environment-solution-title":"Solution","listing-page-order-by":"Order By","listing-page-order-by-default":"Default","listing-page-order-by-date-asc":"Oldest","listing-page-order-by-date-desc":"Newest","listing-page-order-by-number-desc":"High to Low","listing-page-order-by-number-asc":"Low to High","listing-page-field-date":"Date","listing-page-field-title":"Title","listing-page-field-description":"Description","listing-page-field-author":"Author","listing-page-field-filename":"File Name","listing-page-field-filemodified":"Modified","listing-page-field-subtitle":"Subtitle","listing-page-field-readingtime":"Reading Time","listing-page-field-wordcount":"Word Count","listing-page-field-categories":"Categories","listing-page-minutes-compact":"{0} min","listing-page-category-all":"All","listing-page-no-matches":"No matching items","listing-page-words":"{0} words","listing-page-filter":"Filter","draft":"Draft"},"metadata":{"lang":"en","fig-responsive":true,"quarto-version":"1.5.55","theme":"materia","title":"503 Extract function"},"extensions":{"book":{"multiFile":true}}}},"projectFormats":["html"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"entries":[],"headings":[]} | ||
{"headings":[],"entries":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"headings":[],"entries":[]} | ||
{"entries":[],"headings":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"entries":[],"headings":[]} | ||
{"headings":[],"entries":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"headings":[],"entries":[]} | ||
{"entries":[],"headings":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"headings":[],"entries":[]} | ||
{"entries":[],"headings":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"headings":[],"entries":[]} | ||
{"entries":[],"headings":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"entries":[],"headings":[]} | ||
{"headings":[],"entries":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"headings":[],"entries":[]} | ||
{"entries":[],"headings":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"entries":[],"headings":["background","prior-to-traveling","on-the-day","setup","in-your-web-browser-with-shinylive","optional-on-your-laptop-with-vs-code-or-positron"]} | ||
{"headings":["background","prior-to-traveling","on-the-day","setup","in-your-web-browser-with-shinylive","optional-on-your-laptop-with-vs-code-or-positron"],"entries":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"entries":[],"headings":[]} | ||
{"headings":[],"entries":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"entries":[],"headings":[]} | ||
{"headings":[],"entries":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"headings":["overview"],"entries":[]} | ||
{"entries":[],"headings":["overview"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"entries":[],"headings":[]} | ||
{"headings":[],"entries":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"headings":[],"entries":[]} | ||
{"entries":[],"headings":[]} |
2 changes: 1 addition & 1 deletion
2
_freeze/docs/exercises/express-305-dynamic-ui/index/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
_freeze/docs/exercises/express-306-navset/index/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
title: "503 Extract function" | ||
title: "306 Extract function" | ||
--- | ||
|
||
```{python} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Use `ui.navset_tabs` and `ui.nav` to put the dataframe output on a second tab. | ||
Modify the page layout by using `with ui.navset_tab()` and `with ui.nav_panel()` to create a tabbed layout. Your app should show the plots on a tab called "Error" and the data on a tab called "Data". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from shiny import ui, render, reactive, App | ||
import pandas as pd | ||
from pathlib import Path | ||
from plots import temp_distirbution, daily_error | ||
import shiny.experimental as x | ||
|
||
infile = Path(__file__).parent / "weather.csv" | ||
weather = pd.read_csv(infile) | ||
weather["error"] = weather["observed_temp"] - weather["forecast_temp"] | ||
|
||
|
||
card1 = x.ui.card(ui.output_plot("Plot")) | ||
tab1 = ui.nav( | ||
"Tab1", | ||
card1, | ||
ui.output_text("some_text"), | ||
) | ||
tab2 = ui.nav("Tab2", ui.output_data_frame("data")) | ||
tab3 = ui.nav("Tab3", ui.output_image("image")) | ||
ui.navset_tab(tab1, tab2, tab3) | ||
|
||
|
||
app_ui = ui.page_fluid( | ||
ui.layout_sidebar( | ||
ui.panel_sidebar( | ||
ui.input_date_range("dates", "Date", start="2022-01-01", end="2022-01-30"), | ||
ui.input_selectize( | ||
"cities", | ||
"Select Cities", | ||
weather["city"].unique().tolist(), | ||
selected="BUFFALO", | ||
multiple=True, | ||
), | ||
ui.input_slider("alpha", "Plot Alpha", value=0.5, min=0, max=1), | ||
width=3, | ||
), | ||
ui.panel_main( | ||
ui.output_plot("error_distribution"), | ||
ui.output_plot("error_by_day"), | ||
ui.output_data_frame("data"), | ||
), | ||
) | ||
) | ||
|
||
|
||
def server(input, output, session): | ||
@reactive.Calc | ||
def filtered_data(): | ||
df = weather.copy() | ||
df = df[df["city"].isin(input.cities())] | ||
df["date"] = pd.to_datetime(df["date"]) | ||
dates = pd.to_datetime(input.dates()) | ||
df = df[(df["date"] > dates[0]) & (df["date"] <= dates[1])] | ||
return df | ||
|
||
@output | ||
@render.plot | ||
def error_distribution(): | ||
return temp_distirbution(filtered_data()) | ||
|
||
@output | ||
@render.plot | ||
def error_by_day(): | ||
return daily_error(filtered_data(), input.alpha()) | ||
|
||
@output | ||
@render.data_frame | ||
def data(): | ||
return filtered_data() | ||
|
||
|
||
app = App(app_ui, server) |
65 changes: 65 additions & 0 deletions
65
docs/exercises/express-306-navset/problem/app-solution-core.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from shiny import ui, render, reactive, App | ||
import pandas as pd | ||
from pathlib import Path | ||
from plots import temp_distirbution, daily_error | ||
|
||
infile = Path(__file__).parent / "weather.csv" | ||
weather = pd.read_csv(infile) | ||
weather["error"] = weather["observed_temp"] - weather["forecast_temp"] | ||
|
||
app_ui = ui.page_fluid( | ||
ui.panel_title("Weather error"), | ||
ui.layout_sidebar( | ||
ui.panel_sidebar( | ||
ui.input_date_range("dates", "Date", start="2022-01-01", end="2022-01-30"), | ||
ui.input_selectize( | ||
"cities", | ||
"Select Cities", | ||
weather["city"].unique().tolist(), | ||
selected="BUFFALO", | ||
multiple=True, | ||
), | ||
ui.input_slider("alpha", "Plot Alpha", value=0.5, min=0, max=1), | ||
width=3, | ||
), | ||
ui.panel_main( | ||
ui.navset_tab( | ||
ui.nav( | ||
"Error", | ||
ui.output_plot("error_distribution"), | ||
ui.output_plot("error_by_day"), | ||
), | ||
ui.nav("Data", ui.output_data_frame("data")), | ||
) | ||
), | ||
), | ||
) | ||
|
||
|
||
def server(input, output, session): | ||
@reactive.Calc | ||
def filtered_data(): | ||
df = weather.copy() | ||
df = df[df["city"].isin(input.cities())] | ||
df["date"] = pd.to_datetime(df["date"]) | ||
dates = pd.to_datetime(input.dates()) | ||
df = df[(df["date"] > dates[0]) & (df["date"] <= dates[1])] | ||
return df | ||
|
||
@output | ||
@render.plot | ||
def error_distribution(): | ||
return temp_distirbution(filtered_data()) | ||
|
||
@output | ||
@render.plot | ||
def error_by_day(): | ||
return daily_error(filtered_data(), input.alpha()) | ||
|
||
@output | ||
@render.data_frame | ||
def data(): | ||
return filtered_data() | ||
|
||
|
||
app = App(app_ui, server) |
Oops, something went wrong.