-
Notifications
You must be signed in to change notification settings - Fork 21
Data Docs #320
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
Merged
Merged
Data Docs #320
Changes from 9 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
946c3da
Adding pages
elnelson575 626a355
Updates so far
elnelson575 431e43f
Updates
elnelson575 a8b519d
Updates
elnelson575 0e0aaba
additional updates
elnelson575 da8dbc5
Current draft
elnelson575 699424e
Current
elnelson575 266ab00
Updates after chat
elnelson575 9dd6968
Updates
elnelson575 4805903
Notes plus remove old modules
elnelson575 c17f67e
More updates
elnelson575 4049b1f
Updates made
elnelson575 e95251d
Updated with apps
elnelson575 55dd234
Overhaul reading data
cpsievert 4cb680e
Updates to persistent storage
elnelson575 35e1e90
Merge branch 'feat/new-data-docs' of https://github.com/posit-dev/py-…
elnelson575 1c5e67f
Updated content
elnelson575 c0fb77a
additional context
elnelson575 5495740
Progress
elnelson575 69b5748
both ibis examples added
elnelson575 84ef625
More updates
elnelson575 71f6b76
Updates
elnelson575 8fcdfe1
Connect info
elnelson575 0a7074b
Added link
elnelson575 8b72ab7
Switching order
elnelson575 d94ff03
Correction
elnelson575 ed4d240
Added notif
elnelson575 7316570
Simplified
elnelson575 0d24fe7
wip updates to persistent data article
cpsievert fe6aa14
Added reading from remote
elnelson575 236b9d4
Merge branch 'feat/new-data-docs' of https://github.com/posit-dev/py-…
elnelson575 85c129a
finish brain dump on persistent data
cpsievert 9d8dc96
Remove link in Essentials section
cpsievert f56a135
Small edits
elnelson575 ee9a24d
Merge branch 'feat/new-data-docs' of https://github.com/posit-dev/py-…
elnelson575 bf16744
Corrections to first example
elnelson575 ae744ed
Corrected GoogleSheets example
elnelson575 0029cb7
Smoothed out the string/boolean thing
elnelson575 a71285b
Restoring paste error in setup for sheets
elnelson575 44ad71c
Removed try except at start
elnelson575 51e3f27
Updates to dotenv
elnelson575 ea0e918
Update docs/reading-data.qmd
elnelson575 5eba31e
Minor updates to wording
elnelson575 905e4ac
Merge branch 'feat/new-data-docs' of https://github.com/posit-dev/py-…
elnelson575 8ac4e62
small changes/improvements
cpsievert a9ea13c
QA on code up to cloud store
elnelson575 e0b73ed
Merge branch 'feat/new-data-docs' of https://github.com/posit-dev/py-…
elnelson575 26d9a3e
More corrections to reading data
elnelson575 e357af0
More correcdtions to reaction section
elnelson575 00cc639
Final corrections for ibis
elnelson575 4656336
small changes/improvements
cpsievert 6e59994
Update docs/persistent-storage.qmd
cpsievert 67e0ca4
Updating s3
elnelson575 ca6c439
Merge branch 'feat/new-data-docs' of https://github.com/posit-dev/py-…
elnelson575 099a8b8
Moving some examples to separate app folder, add screenshot
elnelson575 16eeed2
Changing examples
elnelson575 f29f527
Minor grammar edits to reading data
elnelson575 4726423
Minor grammar edits for persistent storage
elnelson575 d335f64
Updating template pages
elnelson575 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,139 @@ | ||
| --- | ||
| title: Persistent storage & writing data | ||
| editor: | ||
| markdown: | ||
| wrap: sentence | ||
| lightbox: | ||
| effect: fade | ||
| --- | ||
|
|
||
| ## Intro | ||
| * Callout connect cloud and support for secrets and persistent storage, link to docs, tehre's a talk that aleks chisolm did at conf | ||
| ## When do you actually need persistent storage | ||
| * You want your application to collect and save information from your users. Example, forms. | ||
| * You need to save a result that your users generate? (ex. save a copy of report generated) | ||
|
|
||
| Note: What are we not talking about here: Auth. Link to any auth docs we have. | ||
|
|
||
| CALLOUT: Connect does both Auth and supports secrets for storage. Link to those docs. | ||
|
|
||
| ### Example with pins and polars? (use a form, save the result) | ||
|
|
||
| TODO: Update this | ||
| ```python | ||
| from shiny import App, Inputs, Outputs, Session, ui, reactive, render | ||
| import pandas as pd | ||
|
|
||
| app_ui = ui.page_fluid( | ||
| ui.h2("Submitted Results"), | ||
| ui.output_data_frame("results_df"), | ||
| ui.input_text("text", "Enter text", value=""), | ||
| ui.input_checkbox("checkbox", "I like checkboxes"), | ||
| ui.input_slider("slider", "My favorite number is:", min=0, max=100, value=50), | ||
| ui.input_action_button("submit", "Submit"), | ||
| ) | ||
|
|
||
|
|
||
| def server(input: Inputs, output: Outputs, session: Session): | ||
| df = reactive.value(pd.DataFrame(columns=["text", "checkbox", "slider"])) | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.submit) | ||
| def results(): | ||
| row = { | ||
| "text": input.text(), | ||
| "checkbox": input.checkbox(), | ||
| "slider": input.slider(), | ||
| } | ||
| row_df = pd.DataFrame([row]) | ||
| new_df = pd.concat([df.get(), row_df], ignore_index=True) | ||
| df.set(new_df) | ||
|
|
||
| @render.data_frame | ||
| def results_df(): | ||
| return render.DataGrid(df.get()) | ||
|
|
||
|
|
||
| app = App(app_ui, server) | ||
| ``` | ||
|
|
||
|
|
||
| ### Example with DuckDB (use a form, save the result) | ||
|
|
||
| #### DuckDB | ||
| ```python | ||
| from shiny import App, Inputs, Outputs, Session, ui, reactive, render | ||
| import duckdb | ||
|
|
||
| con = duckdb.connect("test_db.db") | ||
|
|
||
| app_ui = ui.page_fluid( | ||
| ui.h2("Submitted Results"), | ||
| ui.output_data_frame("results_df"), | ||
| ui.input_text("text", "Enter text", value=""), | ||
| ui.input_checkbox("checkbox", "I like checkboxes"), | ||
| ui.input_slider("slider", "My favorite number is:", min=0, max=100, value=50), | ||
| ui.input_action_button("submit", "Submit"), | ||
| ) | ||
|
|
||
| def server(input: Inputs, output: Outputs, session: Session): | ||
| # Initialize a reactive value so we start with the table visible. | ||
| df = reactive.value(con.sql("SELECT * FROM data").df()) | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.submit) | ||
| def save(): | ||
| row = [input.text(), input.checkbox(), input.slider()] | ||
|
|
||
| # We use a prepared statement here to avoid SQL injection | ||
| con.execute("INSERT INTO data VALUES (?, ?, ?)", row) | ||
| con.commit() | ||
|
|
||
| # Set the reactive value so the table updates | ||
| df.set(con.sql("SELECT * FROM data").df()) | ||
|
|
||
| @render.data_frame | ||
| def results_df(): | ||
| return df() | ||
|
|
||
|
|
||
| app = App(app_ui, server, debug=True) | ||
| ``` | ||
|
|
||
| ## Connecting to databases | ||
elnelson575 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Example connecting with Ibis and saving to db with a form | ||
|
|
||
| ## Deployment options | ||
elnelson575 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Auth - connect callout | ||
elnelson575 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### SQL injection prevention | ||
| Callout near wherever we first execute SQL, be careful, diff libraries have tooling | ||
|
|
||
|
|
||
| ### Connection pooling & transaction locking? | ||
elnelson575 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Note on credentials? (don't use your admin creds in your app, have user creds for db, scope them narrowly, etc.) | ||
elnelson575 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
elnelson575 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
|
|
||
| ### Example Applications | ||
| ::: {.panel-tabset .panel-pills} | ||
|
|
||
| #### Polars | ||
|
|
||
|
|
||
| #### DuckDB | ||
| Outliers app: Reads and writes from DuckDB https://github.com/skaltman/outliers-app-db-python/blob/main/app.py | ||
| Database Explorer: https://shiny.posit.co/py/templates/database-explorer/ | ||
|
|
||
| #### Pandas | ||
| AWS-Community-Builders-App: Process data from a CSV and displays it https://github.com/robertgv/aws-community-builders-dashboard | ||
|
|
||
| #### Sqlite3 | ||
| Database monitoring app: https://github.com/posit-dev/py-shiny-templates/tree/main/monitor-database | ||
|
|
||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.