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

🚀 Release 0.2.8 #53

Merged
merged 5 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 8 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# Release 0.2.7
# Release 0.2.8

## 0.2.7 (2023-10-18)
## 0.2.8 (2023-12-10)

### Features

- New component: `Table`
- - Fast components are callable to update attributes. For example, to update the `page_size` attribute of `Table`, do `Table(page_size=20)`. At the same time, Fast Components can also be used as non-callable objects.
- Pandas DataFrame is rendered as a `Table`.
- "About" button displays the function docstring in parse markdown. New utility function to extract function docstring has been incorporated for this feature. This is, however, still experimental.
- Documentation upates, new "Usage Patterns" page.
- New tests.
- Fast Dash now supports Python 3.11.
- On mobile layouts, automatically close sidebars when submit is clicked. Thank you @seanbearden for the issue.
- New examples in the documentation.
- Added some new examples to README.

### Deprecations
### Fixes

- Support for Python 3.7 has been deprecated.
- Set image component width to 100%.
- Fix: If input is None, it's not automatically transformed.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@
<p align="center">
<em>Open source, Python-based tool to build prototypes lightning fast ⚡</em>
</p>

<p align="center">
<a href="https://pypi.python.org/pypi/fast_dash">
<img src="https://img.shields.io/pypi/v/fast_dash?color=%2334D058"
<img src="https://img.shields.io/pypi/v/fast_dash?color=%2334D058&labelColor=black"
alt = "Release Status">
</a>

<a href="https://github.com/dkedar7/fast_dash/actions">
<img src="https://github.com/dkedar7/fast_dash/actions/workflows/release.yml/badge.svg" alt="CI Status">
</a>


<a href="https://github.com/dkedar7/fast_dash/blob/main/LICENSE">
<img src="https://img.shields.io/github/license/dkedar7/fast_dash" alt="MIT License">
<img src="https://img.shields.io/github/license/dkedar7/fast_dash?color=2334D058&labelColor=black" alt="MIT License">
</a>

<a href="https://docs.fastdash.app/">
<img src="https://img.shields.io/badge/Docs-MkDocs-<COLOR>.svg" alt="Documentation">
<img src="https://img.shields.io/badge/Docs-MkDocs-<COLOR>.svg?labelColor=black" alt="Documentation">
</a>

<a href="https://pepy.tech/project/fast-dash">
<img src="https://static.pepy.tech/personalized-badge/fast-dash?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads" alt="Downloads">
</a>
Expand Down Expand Up @@ -117,6 +111,14 @@ def multiple_output_components(start_date: datetime.date, # Adds a date componen
```
![Simple example with multiple inputs](https://storage.googleapis.com/fast_dash/0.2.7/Multiple%20components%20using%20mosaic.png)

In just a few lines of code, you can also add a chat component.

![Simple chat](https://storage.googleapis.com/fast_dash/0.2.8/FD%20chat.png)

You can use your favorite Python libraries. Here's an example of an advanced geospatial application built using `geemap` and Google Earth Engine.

![Water spectral indices](https://storage.googleapis.com/fast_dash/0.2.8/FD%20water%20spectral%20indices.png)

## About

Read different ways to build Fast Dash apps and additional details by navigating to the [project documentation](https://docs.fastdash.app/).
Expand Down
15 changes: 15 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# History

# Release 0.2.8

## 0.2.8 (2023-12-10)

### Features

- On mobile layouts, automatically close sidebars when submit is clicked. Thank you @seanbearden for the issue.
- New examples in the documentation.
- Added some new examples to README.

### Fixes

- Set image component width to 100%.
- Fix: If input is None, it's not automatically transformed.

## 0.2.7 (2023-10-18)

### Features
Expand Down
21 changes: 15 additions & 6 deletions fast_dash/Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dash
from dash import Input, Output, State, dcc, html, ctx, Patch
from dash.exceptions import PreventUpdate
from flask import request

import dash_bootstrap_components as dbc
import dash_mantine_components as dmc
Expand Down Expand Up @@ -670,23 +671,31 @@ def generate_layout(self):

def callbacks(self, app):
@app.app.callback(
[Output("input-group", "style")],
[Input("sidebar-button", "opened")],
[Output("input-group", "style"), Output("sidebar-button", "opened")],
[Input("sidebar-button", "opened"), Input("submit_inputs", "n_clicks")],
[State("input-group", "style")],
)
def toggle_sidebar(opened, input_style):
def toggle_sidebar(opened, submit_clicks, input_style):
user_agent = request.headers.get("User-Agent")
input_style = {} if input_style is None else input_style

# Condition to collapse the sidebar:
# Burger icon is closed or no inputs are specified
if not opened or self.app.inputs == [] or self.app.inputs is None:
input_style.update({"display": "none"})
opened = False

# Another condition to collapse the sidebar:
# User is on mobile and the inputs are submitted
elif ctx.triggered_id == "submit_inputs" and "Mobi" in user_agent:
input_style.update({"display": "none"})
opened = False

# Expand by default
else:
input_style.update({"display": "block"})

return (input_style,)
return (input_style, opened)

# Optional callbacks specific to the layout
@app.app.callback(
Expand Down Expand Up @@ -1204,7 +1213,7 @@ def _infer_output_components(func, outputs, output_labels):
),
component_property="value",
placeholder="",
tag="Text"
tag="Text",
)

TextArea = Fastify(component=dbc.Textarea(), component_property="value", tag="Text")
Expand Down Expand Up @@ -1267,7 +1276,7 @@ def _infer_output_components(func, outputs, output_labels):
style={
"object-fit": "contain",
"max-height": "90%",
"max-width": "80%",
"max-width": "100%",
"height": "auto",
}
),
Expand Down
2 changes: 1 addition & 1 deletion fast_dash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Kedar Dabhadkar"""
__email__ = "[email protected]"
__version__ = "0.2.7"
__version__ = "0.2.8"

from fast_dash.Components import (
Graph,
Expand Down
5 changes: 4 additions & 1 deletion fast_dash/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ def _transform_inputs(inputs, tags):

transformed_inputs = []
for inp, tag in zip(inputs, tags):
if tag == "Image":
if inp is None:
transformed_inputs.append(inp)

elif tag == "Image":
transformed_inputs.append(_b64_to_pil(inp))

else:
Expand Down
58 changes: 39 additions & 19 deletions tests/test_fast_dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,15 @@ def test_fdfd011_base_layout(dash_duo):

app = FastDash(callback_fn=simple_text_to_multiple_outputs, layout="base")
assert app.output_labels == ["FIG", "RETURN_SOME_TEXT"]



def test_fdfd012_about_button_true(dash_duo):
"Test the about button auto-documentation generation"

def example_function(param1, param2=42):
"""
An example function for demonstration.

Args:
param1 (str): Description for parameter 1.
param2 (int, optional): Description for parameter 2. Defaults to 42.
Expand All @@ -238,12 +239,7 @@ def example_function(param1, param2=42):
"""
return True


app = FastDash(
callback_fn=example_function,
inputs=Text,
outputs=Text
).app
app = FastDash(callback_fn=example_function, inputs=Text, outputs=Text).app

dash_duo.start_server(app)
dash_duo.wait_for_text_to_equal("#title8888928", "Example Function", timeout=4)
Expand All @@ -256,7 +252,9 @@ def example_function(param1, param2=42):
displayed_markdown = dash_duo.find_element("#about-modal-body").text

assert "Example Function" in displayed_markdown, "Docstring absent in about (1)"
assert "Description for parameter 1." in displayed_markdown, "Docstring absent in about (2)"
assert (
"Description for parameter 1." in displayed_markdown
), "Docstring absent in about (2)"


def test_fdfd013_about_button_false(dash_duo):
Expand All @@ -265,7 +263,7 @@ def test_fdfd013_about_button_false(dash_duo):
def example_function(param1, param2=42):
"""
An example function for demonstration.

Args:
param1 (str): Description for parameter 1.
param2 (int, optional): Description for parameter 2. Defaults to 42.
Expand All @@ -274,12 +272,9 @@ def example_function(param1, param2=42):
bool: Description for return value.
"""
return True

app = FastDash(
callback_fn=example_function,
inputs=Text,
outputs=Text,
about=False
callback_fn=example_function, inputs=Text, outputs=Text, about=False
).app

dash_duo.start_server(app)
Expand All @@ -295,7 +290,7 @@ def test_fdfd014_about_button_custom(dash_duo):
def example_function(param1, param2=42):
"""
An example function for demonstration.

Args:
param1 (str): Description for parameter 1.
param2 (int, optional): Description for parameter 2. Defaults to 42.
Expand All @@ -304,13 +299,13 @@ def example_function(param1, param2=42):
bool: Description for return value.
"""
return True

# When about argument is custom text
app = FastDash(
callback_fn=example_function,
inputs=Text,
outputs=Text,
about="Custom about section"
about="Custom about section",
).app

dash_duo.start_server(app)
Expand All @@ -323,4 +318,29 @@ def example_function(param1, param2=42):
# Grab the generated markdown text
displayed_markdown = dash_duo.find_element("#about-modal-body").text

assert "Custom about section" in displayed_markdown, "Docstring mismatch in about (3)"
assert (
"Custom about section" in displayed_markdown
), "Docstring mismatch in about (3)"


def test_fdfd015_close_sidebar(dash_duo):
"Test closing the sidebar"

app = FastDash(
callback_fn=simple_text_to_text_function, inputs=Text, outputs=Text
).app

dash_duo.start_server(app)
dash_duo.wait_for_text_to_equal(
"#title8888928", "Simple Text To Text Function", timeout=4
)

# Click sidebar toggle
dash_duo.multiple_click("#sidebar-button", 1)

# Find the style of the sidebar
sidebar_style = dash_duo.find_element("#input-group").get_attribute("style")
sidebar_style = dict(
item.split(":") for item in sidebar_style.strip(";").split("; ") if item
)
assert sidebar_style["display"].strip() == "none", "Sidebar did not close"