Avaiga / taipy-gui

Graphical User Interface generator for Taipy
Apache License 2.0
60 stars 20 forks source link

support custom user content function #1017

Closed FredLL-Avaiga closed 11 months ago

FredLL-Avaiga commented 11 months ago

Addresses the generic part of taipy#444.

The user can create content provider functions that, depending on a content type (set to the content property of a part), converts it into HTML code that Taipy can integrate in a page.

A provider would be declared as :

from taipy.gui import Gui

from plotly.graph_objs import Figure

Gui.register_content_provider(Figure, get_figure_html)

def get_figure_html(figure: Figure):
    return figure.to_html()

Then using the provider is as simple as

import plotly.express as px

md = """
# Taipy Plotly Provider

<|part|content={px.scatter(df, x="sepal_length", y="sepal_width", color="species")}|>

"""

Gui(md).run()
github-actions[bot] commented 11 months ago

β˜‚οΈ Python Coverage

current status: βœ…

Overall Coverage

Lines Covered Coverage Threshold Status
5276 4522 86% 85% 🟒

New Files

No new covered files...

Modified Files

File Coverage Status
src/taipy/gui/_renderers/builder.py 83% 🟒
src/taipy/gui/_renderers/factory.py 99% 🟒
src/taipy/gui/gui.py 87% 🟒
src/taipy/gui/types.py 92% 🟒
src/taipy/gui/utils/init.py 100% 🟒
src/taipy/gui/utils/_evaluator.py 88% 🟒
src/taipy/gui/utils/types.py 86% 🟒
TOTAL 91% 🟒

updated for commit: 1f74dda by action🐍

github-actions[bot] commented 11 months ago

Coverage report for gui

Branches coverage not met for global: expected >=80%, but got 62.432675044883304%
St.:grey_question:
Category Percentage Covered / Total
🟒 Statements 80.85% 2293/2836
🟑 Branches 62.43% 1391/2228
🟑 Functions 75.38% 401/532
🟒 Lines 81.21% 2127/2619

Test suite run success

334 tests passing in 36 suites.

Report generated by πŸ§ͺjest coverage report action from 1f74dda0747b36e3fa74c29e67e336e2b70e9407

FredLL-Avaiga commented 11 months ago

Good catch, tx

On Sat, Nov 18, 2023, 13:12 dinhlongnguyen @.***> wrote:

@.**** approved this pull request.

LGTM

In src/taipy/gui/gui.py https://github.com/Avaiga/taipy-gui/pull/1017#discussion_r1398198682:

@@ -686,27 +686,48 @@ def _get_user_content_url( return f"/{Gui.__USER_CONTENT_URL}/{path or ''}?{urlencode(qargs)}"

 def __serve_user_content(self, path: str) -> t.Any:
  • if hasattr(self, "on_user_content") and callable(self.on_user_content):
  • self.__set_client_id_in_context()
  • self.__set_client_id_in_context()
  • qargs: t.Dict[str, str] = {}
  • qargs.update(request.args)
  • qargs.pop(Gui.__ARG_CLIENT_ID, None)
  • cb_function_name = qargs.get("custom_user_content_cb")
  • cb_function = None
  • if cb_function_name:
  • cb_function = self._get_user_function(cb_function_name)
  • if not callable(cb_function):
  • parts = cb_function_name.split(".", 2)

From what I am seeing in the code we only make use of 2 items in the split. Max split should be 1 instead of 2 if you want a list of 2 elements according to this https://www.w3schools.com/python/ref_string_split.asp.

β€” Reply to this email directly, view it on GitHub https://github.com/Avaiga/taipy-gui/pull/1017#pullrequestreview-1738391014, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVQBA5F4IUK7E6Y5BN6CEOTYFCQ4FAVCNFSM6AAAAAA7QHBBLKVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTOMZYGM4TCMBRGQ . You are receiving this because you were assigned.Message ID: @.***>