text
stringlengths
0
5.92k
from datetime import datetime import taipy.gui.builder as tgb from taipy.gui import Gui def test_date_builder_1(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) with tgb.Page(frame=None) as page: tgb.date(id="date", date="{date}") expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) def test_date_builder_2(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) with tgb.Page(frame=None) as page: tgb.date(id="date", date="{date}", with_time=True) expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", "withTime={true}", ] helpers.test_control_builder(gui, page, expected_list)
import taipy.gui.builder as tgb from taipy.gui import Gui def test_indicator_builder(gui: Gui, test_client, helpers): gui._bind_var_val("val", 15) with tgb.Page(frame=None) as page: tgb.indicator(display=12, value="{val}", min=1, max=20, format="%.2f") expected_list = [ "<Indicator", 'libClassName="taipy-indicator"', "defaultValue={15}", "display={12.0}", 'format="%.2f"', "max={20.0}", "min={1.0}", "value={_TpN_tpec_TpExPr_val_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list)
import taipy.gui.builder as tgb from taipy.gui import Gui def test_navbar_builder(gui: Gui, test_client, helpers): gui._bind_var_val( "navlov", [ ("/page1", "Page 1"), ("/page2", "Page 2"), ("/page3", "Page 3"), ("/page4", "Page 4"), ], ) with tgb.Page(frame=None) as page: tgb.navbar(lov="{navlov}") expected_list = [ "<NavBar", 'defaultLov="[[&quot;/page1&quot;, &quot;Page 1&quot;], [&quot;/page2&quot;, &quot;Page 2&quot;], [&quot;/page3&quot;, &quot;Page 3&quot;], [&quot;/page4&quot;, &quot;Page 4&quot;]]"', "lov={_TpL_tpec_TpExPr_navlov_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list)
import taipy.gui.builder as tgb from taipy.gui import Gui def test_part_builder_1(gui: Gui, helpers): with tgb.Page(frame=None) as page: with tgb.part(class_name="class1"): tgb.text(value="This is a part") expected_list = ["<Part", "This is a part"] helpers.test_control_builder(gui, page, expected_list)
import inspect from taipy.gui import Gui def test_slider_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) md_string = "<|{x}|slider|>" expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0', "defaultValue={10}", "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_with_min_max(gui: Gui, test_client, helpers): gui._bind_var_val("x", 0) md_string = "<|{x}|slider|min=-10|max=10|>" expected_list = ["<Slider", "min={-10.0}", "max={10.0}", "defaultValue={0}"] helpers.test_control_md(gui, md_string, expected_list) def test_slider_with_dict_labels_md(gui: Gui, helpers): sel = "Item 1" # noqa: F841 labels = {"Item 1": "Label Start", "Item 3": "Label End"} # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|{sel}|slider|lov=Item 1;Item 2;Item 3|labels={labels}|>" expected_list = [ "<Slider", 'labels="{&quot;Item 1&quot;: &quot;Label Start&quot;, &quot;Item 3&quot;: &quot;Label End&quot;}"', ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_with_boolean_labels_md(gui: Gui, helpers): sel = "Item 1" # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|{sel}|slider|lov=Item 1;Item 2;Item 3|labels|>" expected_list = ["<Slider", "labels={true}"] helpers.test_control_md(gui, md_string, expected_list) def test_slider_items_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", "Item 1") md_string = "<|{x}|slider|lov=Item 1;Item 2;Item 3|text_anchor=left|>" expected_list = [ "<Slider", 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"', "value={_TpLv_tpec_TpExPr_x_TPMDL_0}", 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"', 'defaultValue="[&quot;Item 1&quot;]"', 'textAnchor="left"', ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_text_anchor_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", "Item 1") md_string = "<|{x}|slider|text_anchor=NoNe|>" expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", 'textAnchor="none"', ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_text_anchor_default_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", "Item 1") md_string = "<|{x}|slider|items=Item 1|>" expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", 'textAnchor="bottom"', ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_array_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", [10, 20]) md_string = "<|{x}|slider|>" expected_list = [ "<Slider", 'updateVarName="_TpLn_tpec_TpExPr_x_TPMDL_0"', "value={_TpLn_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = '<taipy:slider value="{x}" />' expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "defaultValue={10}", "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_slider_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = "<taipy:slider>{x}</taipy:slider>" expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "defaultValue={10}", "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. from taipy.gui import Gui def test_button_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") md_string = "<|Hello {name}|button|id={btn_id}|>" expected_list = ["<Button", 'defaultLabel="Hello World!"', "label={tp_TpExPr_Hello_name_TPMDL_0_0"] helpers.test_control_md(gui, md_string, expected_list) def test_button_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") md_string = "<|button|label=Hello {name}|id={btn_id}|>" expected_list = ["<Button", 'defaultLabel="Hello World!"', "label={tp_TpExPr_Hello_name_TPMDL_0_0"] helpers.test_control_md(gui, md_string, expected_list) def test_button_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") html_string = '<taipy:button label="Hello {name}" id="{btn_id}" />' expected_list = ["<Button", 'defaultLabel="Hello World!"', "label={tp_TpExPr_Hello_name_TPMDL_0_0"] helpers.test_control_html(gui, html_string, expected_list) def test_button_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") html_string = '<taipy:button id="{btn_id}">Hello {name}</taipy:button>' expected_list = ["<Button", 'defaultLabel="Hello World!"', "label={tp_TpExPr_Hello_name_TPMDL_0_0"] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_selector_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", ["l1", "l2"]) gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True}) md_string = "<|{selected_val}|selector|properties=selector_properties|multiple|>" expected_list = [ "<Selector", 'defaultLov="[[&quot;l1&quot;, &quot;v1&quot;], [&quot;l2&quot;, &quot;v2&quot;], [&quot;l3&quot;, &quot;v3&quot;]]"', 'defaultValue="[&quot;l1&quot;, &quot;l2&quot;]"', "filter={true}", "multiple={true}", 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_selector_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", "Item 2") md_string = "<|{selected_val}|selector|lov=Item 1;Item 2; This is a another value|>" expected_list = [ "<Selector", 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot; This is a another value&quot;]"', 'defaultValue="[&quot;Item 2&quot;]"', 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_selector_md_3(gui: Gui, test_client, helpers): gui._bind_var_val("elt", None) gui._bind_var_val( "scenario_list", [{"id": "1", "name": "scenario 1"}, {"id": "3", "name": "scenario 3"}, {"id": "2", "name": "scenario 2"}], ) gui._bind_var_val("selected_obj", {"id": "1", "name": "scenario 1"}) md_string = '<|{selected_obj}|selector|lov={scenario_list}|type=Scenario|adapter={lambda elt: (elt["id"], elt["name"])}|not propagate|>' expected_list = [ "<Selector", 'defaultLov="[[&quot;1&quot;, &quot;scenario 1&quot;], [&quot;3&quot;, &quot;scenario 3&quot;], [&quot;2&quot;, &quot;scenario 2&quot;]]"', 'defaultValue="[&quot;1&quot;]"', "lov={_TpL_tpec_TpExPr_scenario_list_TPMDL_0}", "propagate={false}", 'updateVars="lov=_TpL_tpec_TpExPr_scenario_list_TPMDL_0"', 'updateVarName="_TpLv_tpec_TpExPr_selected_obj_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_obj_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_selector_html_1_1(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", ["l1", "l2"]) gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True}) html_string = '<taipy:selector value="{selected_val}" properties="selector_properties" multiple="True"/>' expected_list = [ "<Selector", 'defaultLov="[[&quot;l1&quot;, &quot;v1&quot;], [&quot;l2&quot;, &quot;v2&quot;], [&quot;l3&quot;, &quot;v3&quot;]]"', 'defaultValue="[&quot;l1&quot;, &quot;l2&quot;]"', "filter={true}", "multiple={true}", 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_selector_html_1_2(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", ["l1", "l2"]) gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True}) html_string = '<taipy:selector properties="selector_properties" multiple="True">{selected_val}</taipy:selector>' expected_list = [ "<Selector", 'defaultLov="[[&quot;l1&quot;, &quot;v1&quot;], [&quot;l2&quot;, &quot;v2&quot;], [&quot;l3&quot;, &quot;v3&quot;]]"', 'defaultValue="[&quot;l1&quot;, &quot;l2&quot;]"', "filter={true}", "multiple={true}", 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_selector_html_2_1(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", "Item 2") html_string = '<taipy:selector value="{selected_val}" lov="Item 1;Item 2; This is a another value" />' expected_list = [ "<Selector", 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot; This is a another value&quot;]"', 'defaultValue="[&quot;Item 2&quot;]"', 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_selector_html_2_2(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", "Item 2") html_string = '<taipy:selector lov="Item 1;Item 2; This is a another value">{selected_val}</taipy:selector>' expected_list = [ "<Selector", 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot; This is a another value&quot;]"', 'defaultValue="[&quot;Item 2&quot;]"', 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
import inspect from taipy.gui import Gui def test_input_md(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|{x}|input|>" expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="text"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_password_md(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|{x}|input|password|>" expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="password"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_input_html_1(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) html_string = '<taipy:input value="{x}" />' expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="text"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_password_html(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) html_string = '<taipy:input value="{x}" password="True" />' expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="password"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_input_html_2(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) html_string = "<taipy:input>{x}</taipy:input>" expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="text"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_tree_md(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") md_string = "<|{value}|tree|lov=Item 1;Item 2;Item 3|>" expected_list = [ "<TreeView", 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"', 'defaultValue="[&quot;Item 1&quot;]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_tree_expanded_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") md_string = "<|{value}|tree|lov=Item 1;Item 2;Item 3|not expanded|>" expected_list = [ "<TreeView", 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"', 'defaultValue="[&quot;Item 1&quot;]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", "expanded={false}", ] helpers.test_control_md(gui, md_string, expected_list) def test_tree_expanded_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") gui._bind_var_val("expa", ["Item1"]) md_string = "<|{value}|tree|lov=Item 1;Item 2;Item 3|expanded={expa}|>" expected_list = [ "<TreeView", 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"', 'defaultValue="[&quot;Item 1&quot;]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", 'defaultExpanded="[&quot;Item1&quot;]"', "expanded={tpec_TpExPr_expa_TPMDL_0}", 'updateVars="expanded=tpec_TpExPr_expa_TPMDL_0', ] helpers.test_control_md(gui, md_string, expected_list) def test_tree_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") html_string = '<taipy:tree lov="Item 1;Item 2;Item 3">{value}</taipy:tree>' expected_list = [ "<TreeView", 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"', 'defaultValue="[&quot;Item 1&quot;]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_tree_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") html_string = '<taipy:tree lov="Item 1;Item 2;Item 3" value="{value}" />' expected_list = [ "<TreeView", 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"', 'defaultValue="[&quot;Item 1&quot;]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_expandable_md_1(gui: Gui, helpers): md_string = """ <|Expandable section|expandable|not expanded| # This is an expandable section |> """ expected_list = [ "<Expandable", "expanded={false}", 'title="Expandable section"', "<h1", "This is an expandable section", ] helpers.test_control_md(gui, md_string, expected_list) def test_expandable_md_2(gui: Gui, helpers): md_string = """ <|expandable.start|title=Expandable section|not expanded|> # This is an expandable section <|expandable.end|> """ expected_list = [ "<Expandable", "expanded={false}", 'title="Expandable section"', "<h1", "This is an expandable section", ] helpers.test_control_md(gui, md_string, expected_list) def test_expandable_html(gui: Gui, helpers): html_string = '<taipy:expandable title="Expandable section" expanded="false"><h1>This is an expandable section</h1></taipy:expandable >' expected_list = [ "<Expandable", "expanded={false}", 'title="Expandable section"', "<h1", "This is an expandable section", ] helpers.test_control_html(gui, html_string, expected_list)
from datetime import datetime from taipy.gui import Gui def test_date_range_md_1(gui: Gui, test_client, helpers): gui._bind_var_val( "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")] ) md_string = "<|{dates}|date_range|>" expected_list = [ "<DateRange", 'defaultDates="[&quot;2020-12-', 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"', "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_date_range_md_2(gui: Gui, test_client, helpers): gui._bind_var_val( "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")] ) md_string = "<|{dates}|date_range|with_time|label_start=start|label_end=end|>" expected_list = [ "<DateRange", 'defaultDates="[&quot;2020-12-', 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"', "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}", "withTime={true}", 'labelStart="start"', 'labelEnd="end"', ] helpers.test_control_md(gui, md_string, expected_list) def test_date_range_html_1(gui: Gui, test_client, helpers): gui._bind_var_val( "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")] ) html_string = '<taipy:date_range dates="{dates}" />' expected_list = [ "<DateRange", 'defaultDates="[&quot;2020-12-', 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"', "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_date_range_html_2(gui: Gui, test_client, helpers): gui._bind_var_val( "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")] ) html_string = "<taipy:date_range>{dates}</taipy:date_range>" expected_list = [ "<DateRange", 'defaultDates="[&quot;2020-12-', 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"', "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
import os import pathlib from importlib import util from taipy.gui import Gui def test_image_url_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") md_string = "<|{content}|image|>" expected_list = [ "<Image", "content={_TpCi_tpec_TpExPr_content_TPMDL_0}", 'defaultContent="some_url"', ] helpers.test_control_md(gui, md_string, expected_list) def test_image_file_md(gui: Gui, test_client, helpers): with open((pathlib.Path(__file__).parent.parent / "resources" / "fred.png").resolve(), "rb") as content: gui._bind_var_val("content", content.read()) md_string = "<|{content}|image|>" expected_list = [ "<Image", 'defaultContent="data:image/png;base64,', ] if not util.find_spec("magic"): expected_list = ["<Image", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_md(gui, md_string, expected_list) def test_image_path_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", str((pathlib.Path(__file__).parent.parent / "resources" / "fred.png").resolve())) md_string = "<|{content}|image|>" expected_list = [ "<Image", 'defaultContent="/taipy-content/taipyStatic0/fred.png', ] helpers.test_control_md(gui, md_string, expected_list) def test_image_bad_file_md(gui: Gui, test_client, helpers): with open(os.path.abspath(__file__), "rb") as content: gui._bind_var_val("content", content.read()) md_string = "<|{content}|image|>" expected_list = [ "<Image", 'defaultContent="Invalid content: text/x', ] if not util.find_spec("magic"): expected_list = ["<Image", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_md(gui, md_string, expected_list) def test_image_url_html(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") html_string = '<taipy:image content="{content}" on_action="action" />' expected_list = [ "<Image", 'defaultContent="some_url"', 'onAction="action"', ] helpers.test_control_html(gui, html_string, expected_list)
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License.
import inspect from taipy.gui import Gui def test_status_md(gui: Gui, helpers): status = [{"status": "info", "message": "Info Message"}] # noqa: F841 md_string = "<|{status}|status|>" expected_list = [ "<Status", 'defaultValue="[&#x7B;&quot;status&quot;: &quot;info&quot;, &quot;message&quot;: &quot;Info Message&quot;&#x7D;]"', "value={tpec_TpExPr_status_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_md(gui, md_string, expected_list) def test_status_html(gui: Gui, helpers): status = [{"status": "info", "message": "Info Message"}] # noqa: F841 html_string = '<taipy:status value="{status}" />' expected_list = [ "<Status", 'defaultValue="[&#x7B;&quot;status&quot;: &quot;info&quot;, &quot;message&quot;: &quot;Info Message&quot;&#x7D;]"', "value={tpec_TpExPr_status_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_toggle_md(gui: Gui, helpers): md_string = "<|toggle|theme|>" expected_list = ["<Toggle", 'kind="theme"', 'unselectedValue=""'] helpers.test_control_md(gui, md_string, expected_list) def test_toggle_allow_unselected_md(gui: Gui, helpers): md_string = "<|toggle|lov=1;2|allow_unselect|>" expected_list = ["<Toggle", 'unselectedValue=""', "allowUnselect={true}"] helpers.test_control_md(gui, md_string, expected_list) def test_toggle_lov_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", "l1") gui._bind_var_val("lov", [("l1", "v1"), ("l2", "v2")]) md_string = "<|{x}|toggle|lov={lov}|label=Label|>" expected_list = [ "<Toggle", 'defaultLov="[[&quot;l1&quot;, &quot;v1&quot;], [&quot;l2&quot;, &quot;v2&quot;]]"', 'defaultValue="l1"', 'label="Label"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"', 'unselectedValue=""', "value={_TpLv_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_toggle_html_1(gui: Gui, helpers): html_string = '<taipy:toggle theme="True" />' expected_list = ["<Toggle", 'kind="theme"', 'unselectedValue=""'] helpers.test_control_html(gui, html_string, expected_list) def test_toggle_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", "l1") gui._bind_var_val("lov", [("l1", "v1"), ("l2", "v2")]) html_string = '<taipy:toggle lov="{lov}" label="Label">{x}</taipy:toggle>' expected_list = [ "<Toggle", 'defaultLov="[[&quot;l1&quot;, &quot;v1&quot;], [&quot;l2&quot;, &quot;v2&quot;]]"', 'defaultValue="l1"', 'label="Label"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"', 'unselectedValue=""', "value={_TpLv_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_pane_md(gui: Gui, test_client, helpers): gui._bind_var_val("show_pane", False) md_string = """ <|{show_pane}|pane|not persistent| # This is a Pane |> """ expected_list = [ "<Pane", 'anchor="left"', 'updateVarName="_TpB_tpec_TpExPr_show_pane_TPMDL_0"', "open={_TpB_tpec_TpExPr_show_pane_TPMDL_0}", "<h1", "This is a Pane</h1></Pane>", ] helpers.test_control_md(gui, md_string, expected_list) def test_pane_persistent_md(gui: Gui, test_client, helpers): gui._bind_var_val("show_pane", False) md_string = """ <|{show_pane}|pane|persistent| # This is a Pane |> """ expected_list = [ "<Pane", 'anchor="left"', "persistent={true}", 'updateVarName="_TpB_tpec_TpExPr_show_pane_TPMDL_0"', "open={_TpB_tpec_TpExPr_show_pane_TPMDL_0}", "<h1", "This is a Pane</h1></Pane>", ] helpers.test_control_md(gui, md_string, expected_list) def test_pane_html(gui: Gui, test_client, helpers): gui._bind_var_val("show_pane", False) html_string = '<taipy:pane open="{show_pane}" persistent="false"><h1>This is a Pane</h1></taipy:pane>' expected_list = [ "<Pane", 'anchor="left"', 'updateVarName="_TpB_tpec_TpExPr_show_pane_TPMDL_0"', "open={_TpB_tpec_TpExPr_show_pane_TPMDL_0}", "<h1", "This is a Pane</h1></Pane>", ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_text_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) md_string = "<|{x}|>" expected_list = ["<Field", 'dataType="int"', 'defaultValue="10"', "value={tpec_TpExPr_x_TPMDL_0}"] helpers.test_control_md(gui, md_string, expected_list) def test_text_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = '<taipy:text value="{x}" />' expected_list = ["<Field", 'dataType="int"', 'defaultValue="10"', "value={tpec_TpExPr_x_TPMDL_0}"] helpers.test_control_html(gui, html_string, expected_list) def test_text_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = "<taipy:text>{x}</taipy:text>" expected_list = ["<Field", 'dataType="int"', 'defaultValue="10"', "value={tpec_TpExPr_x_TPMDL_0}"] helpers.test_control_html(gui, html_string, expected_list)
import os import pathlib from importlib import util from taipy.gui import Gui def test_file_download_url_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") md_string = "<|{content}|file_download|>" expected_list = [ "<FileDownload", "content={_TpC_tpec_TpExPr_content_TPMDL_0}", 'defaultContent="some_url"', ] helpers.test_control_md(gui, md_string, expected_list) def test_file_download_file_md(gui: Gui, test_client, helpers): with open((pathlib.Path(__file__).parent.parent / "resources" / "fred.png").resolve(), "rb") as content: gui._bind_var_val("content", content.read()) md_string = "<|{content}|file_download|>" expected_list = [ "<FileDownload", 'defaultContent="data:image/png;base64,', ] if not util.find_spec("magic"): expected_list = ["<FileDownload", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_md(gui, md_string, expected_list) def test_file_download_path_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", str((pathlib.Path(__file__).parent.parent / "resources" / "fred.png").resolve())) md_string = "<|{content}|file_download|>" expected_list = [ "<FileDownload", 'defaultContent="/taipy-content/taipyStatic0/fred.png', ] helpers.test_control_md(gui, md_string, expected_list) def test_file_download_any_file_md(gui: Gui, test_client, helpers): with open(os.path.abspath(__file__), "rb") as content: gui._bind_var_val("content", content.read()) md_string = "<|{content}|file_download|>" expected_list = [ "<FileDownload", 'defaultContent="data:text/x', "python;base64,", ] if not util.find_spec("magic"): expected_list = ["<FileDownload", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_md(gui, md_string, expected_list) def test_file_download_url_html(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") html_string = '<taipy:file_download content="{content}" />' expected_list = [ "<FileDownload", 'defaultContent="some_url"', ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_file_selector_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", None) md_string = "<|{content}|file_selector|label=label|on_action=action|>" expected_list = [ "<FileSelector", 'updateVarName="tpec_TpExPr_content_TPMDL_0"', 'label="label"', 'onAction="action"', ] helpers.test_control_md(gui, md_string, expected_list) def test_file_selector_html(gui: Gui, test_client, helpers): gui._bind_var_val("content", None) html_string = '<taipy:file_selector content="{content}" label="label" on_action="action" />' expected_list = [ "<FileSelector", 'updateVarName="tpec_TpExPr_content_TPMDL_0"', 'label="label"', 'onAction="action"', ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_content_md(gui: Gui, helpers): md_string = "<|content|>" expected_list = ["<PageContent"] helpers.test_control_md(gui, md_string, expected_list) def test_content_html(gui: Gui, helpers): html_string = "<taipy:content />" expected_list = ["<PageContent"] helpers.test_control_html(gui, html_string, expected_list)
import inspect from taipy.gui import Gui, Markdown def test_dialog_md_1(gui: Gui, helpers): dialog_open = False # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|dialog|title=This is a Dialog|open={dialog_open}|page=page_test|on_action=validate_action|>" expected_list = [ "<Dialog", 'onAction="validate_action"', 'page="page_test"', 'title="This is a Dialog"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_dialog_md_2(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) partial = gui.add_partial(Markdown("# A partial")) # noqa: F841 dialog_open = False # noqa: F841 md_string = "<|dialog|title=Another Dialog|open={dialog_open}|partial={partial}|on_action=validate_action|>" expected_list = [ "<Dialog", 'page="TaiPy_partials', 'title="Another Dialog"', 'onAction="validate_action"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_dialog_labels_md(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) dialog_open = False # noqa: F841 md_string = ( "<|dialog|title=Another Dialog|open={dialog_open}|page=page_test|labels=Cancel;Validate|close_label=MYClose|>" ) expected_list = [ "<Dialog", 'page="page_test"', 'title="Another Dialog"', 'labels="[&quot;Cancel&quot;, &quot;Validate&quot;]"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', 'closeLabel="MYClose"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_dialog_html_1(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) dialog_open = False # noqa: F841 html_string = ( '<taipy:dialog title="This is a Dialog" open="{dialog_open}" page="page1" on_action="validate_action" />' ) expected_list = [ "<Dialog", 'page="page1"', 'title="This is a Dialog"', 'onAction="validate_action"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_dialog_html_2(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) partial = gui.add_partial(Markdown("# A partial")) # noqa: F841 dialog_open = False # noqa: F841 html_string = ( '<taipy:dialog title="Another Dialog" open="{dialog_open}" partial="{partial}" on_action="validate_action" />' ) expected_list = [ "<Dialog", 'page="TaiPy_partials', 'title="Another Dialog"', 'onAction="validate_action"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_dialog_labels_html(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) dialog_open = False # noqa: F841 html_string = ( '<taipy:dialog title="Another Dialog" open="{dialog_open}" page="page_test" labels="Cancel;Validate" />' ) expected_list = [ "<Dialog", 'page="page_test"', 'title="Another Dialog"', 'labels="[&quot;Cancel&quot;, &quot;Validate&quot;]"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_menu_md(gui: Gui, test_client, helpers): gui._bind_var_val("lov", ["Item 1", "Item 2", "Item 3", "Item 4"]) md_string = "<|menu|lov={lov}|on_action=on_menu_action|>" expected_list = [ "<MenuCtl", 'libClassName="taipy-menu"', 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;, &quot;Item 4&quot;]"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'onAction="on_menu_action"', 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', ] helpers.test_control_md(gui, md_string, expected_list) def test_menu_html(gui: Gui, test_client, helpers): gui._bind_var_val("lov", ["Item 1", "Item 2", "Item 3", "Item 4"]) html_string = '<taipy:menu lov="{lov}" />' expected_list = [ "<MenuCtl", 'libClassName="taipy-menu"', 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;, &quot;Item 4&quot;]"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_layout_md_1(gui: Gui, helpers): md_string = """ <|layout|columns=1 1|gap=1rem| # This is a layout section |> """ expected_list = ["<Layout", 'columns="1 1', 'gap="1rem"', "<h1", "This is a layout section"] helpers.test_control_md(gui, md_string, expected_list) def test_layout_md_2(gui: Gui, helpers): md_string = """ <|layout.start|columns=1 1|gap=1rem|> # This is a layout section <|layout.end|> """ expected_list = ["<Layout", 'columns="1 1', 'gap="1rem"', "<h1", "This is a layout section"] helpers.test_control_md(gui, md_string, expected_list) def test_layout_html(gui: Gui, helpers): html_string = '<taipy:layout columns="1 1" gap="1rem"><h1>This is a layout section</h1></taipy:layout>' expected_list = ["<Layout", 'columns="1 1', 'gap="1rem"', "<h1", "This is a layout section"] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_number_md_1(gui: Gui, helpers): md_string = "<|10|number|>" expected_list = ["<Input", 'value="10"', 'type="number"'] helpers.test_control_md(gui, md_string, expected_list) def test_number_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", "10") md_string = "<|{x}|number|>" expected_list = [ "<Input", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', 'defaultValue="10"', 'type="number"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_number_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = '<taipy:number value="{x}" />' expected_list = [ "<Input", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', 'defaultValue="10"', 'type="number"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_number_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = "<taipy:number>{x}</taipy:number>" expected_list = [ "<Input", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', 'defaultValue="10"', 'type="number"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
from datetime import datetime from taipy.gui import Gui def test_date_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) md_string = "<|{date}|date|>" expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_date_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) md_string = "<|{date}|date|with_time|label=a label|>" expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", "withTime={true}", 'label="a label"', ] helpers.test_control_md(gui, md_string, expected_list) def test_date_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) html_string = '<taipy:date date="{date}" />' expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_date_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) html_string = "<taipy:date>{date}</taipy:date>" expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_indicator_md(gui: Gui, test_client, helpers): gui._bind_var_val("val", 15) md_string = "<|12|indicator|value={val}|min=1|max=20|format=%.2f|>" expected_list = [ "<Indicator", 'libClassName="taipy-indicator"', "defaultValue={15}", "display={12.0}", 'format="%.2f"', "max={20.0}", "min={1.0}", "value={_TpN_tpec_TpExPr_val_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_menu_html(gui: Gui, test_client, helpers): gui._bind_var_val("val", 15) html_string = '<taipy:indicator value="{val}" min="1" max="20" format="%.2f" >12</taipy:indicator>' expected_list = [ "<Indicator", 'libClassName="taipy-indicator"', "defaultValue={15}", "display={12.0}", 'format="%.2f"', "max={20.0}", "min={1.0}", "value={_TpN_tpec_TpExPr_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_navbar_md(gui: Gui, test_client, helpers): gui._bind_var_val( "navlov", [ ("/page1", "Page 1"), ("/page2", "Page 2"), ("/page3", "Page 3"), ("/page4", "Page 4"), ], ) md_string = "<|navbar|lov={navlov}|>" expected_list = [ "<NavBar", 'defaultLov="[[&quot;/page1&quot;, &quot;Page 1&quot;], [&quot;/page2&quot;, &quot;Page 2&quot;], [&quot;/page3&quot;, &quot;Page 3&quot;], [&quot;/page4&quot;, &quot;Page 4&quot;]]"', "lov={_TpL_tpec_TpExPr_navlov_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_navbar_html(gui: Gui, test_client, helpers): gui._bind_var_val( "navlov", [ ("/page1", "Page 1"), ("/page2", "Page 2"), ("/page3", "Page 3"), ("/page4", "Page 4"), ], ) html_string = '<taipy:navbar lov="{navlov}" />' expected_list = [ "<NavBar", 'defaultLov="[[&quot;/page1&quot;, &quot;Page 1&quot;], [&quot;/page2&quot;, &quot;Page 2&quot;], [&quot;/page3&quot;, &quot;Page 3&quot;], [&quot;/page4&quot;, &quot;Page 4&quot;]]"', "lov={_TpL_tpec_TpExPr_navlov_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list)
from taipy.gui import Gui def test_part_md_1(gui: Gui, helpers): md_string = """ <|part|class_name=class1| # This is a part |> """ expected_list = ["<Part", "<h1", "This is a part"] helpers.test_control_md(gui, md_string, expected_list) def test_part_md_2(gui: Gui, helpers): md_string = """ <|part.start|class_name=class1|> # This is a part <|part.end|> """ expected_list = ["<Part", "<h1", "This is a part"] helpers.test_control_md(gui, md_string, expected_list) def test_part_html(gui: Gui, helpers): html_string = '<taipy:part class_name="class1"><h1>This is a part</h1></taipy:part>' expected_list = ["<Part", "<h1", "This is a part"] helpers.test_control_html(gui, html_string, expected_list)
import random import string from example_library import ExampleLibrary from taipy.gui import Gui # Initial value label = "Here is some text" page = """ # Custom elements example ## Fraction: No denominator: <|123|example.fraction|> Denominator is 0: <|321|example.fraction|denominator=0|> Regular: <|355|example.fraction|denominator=113|> ## Custom label: Colored text: <|{label}|example.label|> <|Add a character|button|id=addChar|> <|Remove a character|button|id=removeChar|> """ def on_action(state, id): if id == "addChar": # Add a random character to the end of 'label' state.label += random.choice(string.ascii_letters) elif id == "removeChar": # Remove the first character of 'label' if len(state.label) > 0: state.label = state.label[1:] Gui(page, libraries=[ExampleLibrary()]).run(debug=True)
from .example_library import ExampleLibrary
from taipy.gui.extension import Element, ElementLibrary, ElementProperty, PropertyType class ExampleLibrary(ElementLibrary): def __init__(self) -> None: # Initialize the set of visual elements for this extension library self.elements = { # A static element that displays its properties in a fraction "fraction": Element( "numerator", { "numerator": ElementProperty(PropertyType.number), "denominator": ElementProperty(PropertyType.number), }, render_xhtml=ExampleLibrary._fraction_render, ), # A dynamic element that decorates its value "label": Element( "value", {"value": ElementProperty(PropertyType.dynamic_string)}, # The name of the React component (ColoredLabel) that implements this custom # element, exported as ExampleLabel in front-end/src/index.ts react_component="ExampleLabel", ), } # The implementation of the rendering for the "fraction" static element @staticmethod def _fraction_render(props: dict) -> str: # Get the property values numerator = props.get("numerator") denominator = props.get("denominator") # No denominator or numerator is 0: display the numerator if denominator is None or int(numerator) == 0: return f"<span>{numerator}</span>" # Denominator is zero: display infinity if int(denominator) == 0: return '<span style="font-size: 1.6em">&#8734;</span>' # 'Normal' case return f"<span><sup>{numerator}</sup>/<sub>{denominator}</sub></span>" def get_name(self) -> str: return "example" def get_elements(self) -> dict: return self.elements def get_scripts(self) -> list[str]: # Only one JavaScript bundle for this library. return ["front-end/dist/exampleLibrary.js"]
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- # Demonstrate how to share variable values across multiple clients. # This application creates a thread that increments a value every few seconds. # The value is updated for every client using the state.broadcast() method. # The text of the button that starts or stops the thread is updated on every client's browser # using a direct assignment of the state property because the variable is declared 'shared'. # ----------------------------------------------------------------------------------------- from threading import Event, Thread from time import sleep from taipy.gui import Gui, State, broadcast_callback counter = 0 # Thread management thread = None thread_event = Event() button_texts = ["Start", "Stop"] # Text in the start/stop button (initially "Start") button_text = button_texts[0] # Invoked by the timer def update_counter(state: State, c): # Update all clients state.broadcast("counter", c) def count(event, gui): while not event.is_set(): global counter counter = counter + 1 broadcast_callback(gui, update_counter, [counter]) sleep(2) # Start or stop the timer when the button is pressed def start_or_stop(state): global thread if thread: # Timer is running thread_event.set() thread = None else: # Timer is stopped thread_event.clear() thread = Thread(target=count, args=[thread_event, state.get_gui()]) thread.start() # Update button status. # Because "button_text" is shared, all clients are updated state.button_text = button_texts[1 if thread else 0] page = """# Broadcasting values Counter: <|{counter}|> Timer: <|{button_text}|button|on_action=start_or_stop|> """ # Declare "button_text" as a shared variable. # Assigning a value to a state's 'button_text' property is propagated to all clients Gui.add_shared_variable("button_text") Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- # Demonstrates the use of the 'rebuild' property of the 'chart' control # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # x values: [-10..10] x_range = range(-10, 11) data = {"X": x_range, "Y": [x * x for x in x_range]} types = [("bar", "Bar"), ("line", "Line")] selected_type = types[0] page = """ <|{data}|chart|type={selected_type[0]}|x=X|y=Y|rebuild|> <|{selected_type}|toggle|lov={types}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import datetime from taipy.gui import Gui # Tasks definitions tasks = ["Plan", "Research", "Design", "Implement", "Test", "Deliver"] # Task durations, in days durations = [50, 30, 30, 40, 15, 10] # Planned start dates of tasks start_dates = [ datetime.date(2022, 10, 15), # Plan datetime.date(2022, 11, 7), # Research datetime.date(2022, 12, 1), # Design datetime.date(2022, 12, 20), # Implement datetime.date(2023, 1, 15), # Test datetime.date(2023, 2, 1), # Deliver ] epoch = datetime.date(1970, 1, 1) data = { "start": start_dates, "Task": tasks, # Compute the time span as adatetime (relative to January 1st, 1970) "Date": [epoch + datetime.timedelta(days=duration) for duration in durations], } layout = { "yaxis": { # Sort tasks from top to bottom "autorange": "reversed", # Remove title "title": {"text": ""}, }, } page = """ # Gantt - Simple <|{data}|chart|type=bar|orientation=h|y=Task|x=Date|base=start|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # x values are [-10..10] x_range = range(-10, 11) # The data set that holds both the x and the y values data = {"X": x_range, "Y": [x * x for x in x_range]} page = """ # Basics - X range <|{data}|chart|x=X|y=Y|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Function to plot: x^3/3-x def f(x): return x * x * x / 3 - x # x values: [-2.2, ..., 2.2] x = [(x - 10) / 4.5 for x in range(0, 21)] data = { "x": x, # y: [f(-2.2), ..., f(2.2)] "y": [f(x) for x in x], } shape_size = 0.1 layout = { "shapes": [ # Shape for local maximum (x = -1) { "x0": -1 - shape_size, "y0": f(-1) - 2 * shape_size, "x1": -1 + shape_size, "y1": f(-1) + 2 * shape_size, "fillcolor": "green", "opacity": 0.5, }, # Shape for local minimum (x = 1) { "x0": 1 - shape_size, "y0": f(1) - 2 * shape_size, "x1": 1 + shape_size, "y1": f(1) + 2 * shape_size, "fillcolor": "red", "opacity": 0.5, }, ] } page = """ # Advanced - Annotations <|{data}|chart|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import numpy from taipy.gui import Gui # Return the x and y coordinates of the spiral for the given angle def spiral(th): a = 1.120529 b = 0.306349 r = a * numpy.exp(-b * th) return (r * numpy.cos(th), r * numpy.sin(th)) # Prepare Golden spiral data as a parametric curve (x, y) = spiral(numpy.linspace(-numpy.pi / 13, 4 * numpy.pi, 1000)) # Prepare the heatmap x and y cell sizes along the axes golden_ratio = (1 + numpy.sqrt(5)) / 2.0 # Golden ratio grid_x = [0, 1, 1 + (1 / (golden_ratio**4)), 1 + (1 / (golden_ratio**3)), golden_ratio] grid_y = [0, 1 / (golden_ratio**3), 1 / golden_ratio**3 + 1 / golden_ratio**4, 1 / (golden_ratio**2), 1] # Main value is based on the Fibonacci sequence z = [[13, 3, 3, 5], [13, 2, 1, 5], [13, 10, 11, 12], [13, 8, 8, 8]] # Group all data sets in a single array data = [ { "z": z, }, {"x": numpy.sort(grid_x), "y": numpy.sort(grid_y)}, { "xSpiral": -x + x[0], "ySpiral": y - y[0], }, ] # Axis template: hide all ticks, lines and labels axis = {"range": [0, 2.0], "showgrid": False, "zeroline": False, "showticklabels": False, "ticks": "", "title": ""} layout = { # Use the axis template for both x and y axes "xaxis": axis, "yaxis": axis, } options = { # Hide the color scale of the heatmap "showscale": False } # Chart holds two traces, with different types types = ["heatmap", "scatter"] # x and y values for both traces xs = ["1/x", "2/xSpiral"] ys = ["1/y", "2/ySpiral"] page = """ ## Heatmap - Drawing on top <|{data}|chart|type={types}|z[1]=0/z|x={xs}|y={ys}|layout={layout}|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import random from taipy.gui import Gui # Data set made of two series of random numbers data = {"A": [random.random() for i in range(200)], "B": [random.random() for i in range(200)]} # Names of the two traces names = ["A samples", "B samples"] layout = { # Make the histogram stack the data sets "barmode": "stack" } page = """ # Histogram - Stacked <|{data}|chart|type=histogram|x[1]=A|x[2]=B|name={names}|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Data set data = { "Day": ["Mon", "Tue", "Wed", "Thu", "Fri"], "Values": [10, -5, 20, -10, 30], "Measure": ["absolute", "relative", "relative", "relative", "relative"], } page = """ # Waterfall - Simple <|{data}|chart|type=waterfall|x=Day|y=Values|measure=Measure|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui n_slices = 20 # List: [1..n_slices] # Slices are bigger and bigger values = list(range(1, n_slices + 1)) marker = { # Colors move around the Hue color disk "colors": [f"hsl({360 * (i - 1)/(n_slices - 1)},90%,60%)" for i in values] } layout = { # Hide the legend "showlegend": False } options = { # Hide the texts "textinfo": "none" } page = """ # Pie - Style <|{values}|chart|type=pie|marker={marker}|options={options}|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from datetime import datetime import numpy from taipy.gui import Gui def generate_hand_shapes(): # Retrieve and store the current, local time time_now = datetime.now() hours = time_now.hour minutes = time_now.minute seconds = time_now.second # Compute the angle that represents the hours hours_angle = 360 * ((hours % 12) / 12 + (minutes % 60) / 60 / 60 + (seconds % 60) / 60 / 60 / 60) # Short and thick hand for the hours hours_hand = {"r": [0, 4, 5, 4, 0], "a": [0, hours_angle - 7, hours_angle, hours_angle + 7, 0]} # Compute the angle that represents the minutes minutes_angle = 360 * ((minutes % 60) / 60 + (seconds % 60) / 60 / 60) # Longer and slighly thinner hand for the minutes minutes_hand = {"r": [0, 6, 8, 6, 0], "a": [0, minutes_angle - 4, minutes_angle, minutes_angle + 4, 0]} # Compute the angle that represents the seconds seconds_angle = 360 * (seconds % 60) / 60 # Even longer and thinner hand for the seconds seconds_hand = {"r": [0, 8, 10, 8, 0], "a": [0, seconds_angle - 2, seconds_angle, seconds_angle + 2, 0]} # Build and return the whole data set return [hours_hand, minutes_hand, seconds_hand] # Initialize the data set with the current time data = generate_hand_shapes() layout = { "polar": { "angularaxis": { "rotation": 90, "direction": "clockwise", # One tick every 30 degrees "tickvals": list(numpy.arange(0.0, 360.0, 30)), # Text value for every tick "ticktext": ["XII", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI"], }, "radialaxis": {"angle": 90, "visible": False, "range": [0, 12]}, }, "showlegend": False, } # Options to be used for all three traces base_opts = {"fill": "toself"} # Specific for hours hours_opts = dict(base_opts) hours_opts["fillcolor"] = "#FF0000" # Specific for minutes minutes_opts = dict(base_opts) minutes_opts["fillcolor"] = "#00FF00" # Specific for seconds seconds_opts = dict(base_opts) seconds_opts["fillcolor"] = "#0000FF" # Store all the chart control properties in a single object properties = { # Don't show data point markers "mode": "lines", # Data for the hours "theta[1]": "0/a", "r[1]": "0/r", # Data for the minutes "theta[2]": "1/a", "r[2]": "1/r", # Data for the seconds "theta[3]": "2/a", "r[3]": "2/r", # Options for the three traces "options[1]": hours_opts, "options[2]": minutes_opts, "options[3]": seconds_opts, "line": {"color": "black"}, "layout": layout, } # Update time on every refresh def on_navigate(state, page): state.data = generate_hand_shapes() return page page = """ # Polar - Tick texts <|{data}|chart|type=scatterpolar|properties={properties}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = {"Types": ["Visits", "Downloads", "Prospects", "Invoiced", "Closed"], "Visits": [13873, 10533, 5443, 2703, 908]} layout = { # Stack the areas "funnelmode": "stack", # Hide the legend "showlegend": False, } page = """ # Funnel - Area <|{data}|chart|type=funnelarea|values=Visits|text=Types|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import pandas from taipy.gui import Gui # Source https://en.wikipedia.org/wiki/List_of_United_States_presidential_elections_by_popular_vote_margin percentages = [ (1852, 50.83), (1856, 45.29), (1860, 39.65), (1864, 55.03), (1868, 52.66), (1872, 55.58), (1876, 47.92), (1880, 48.31), (1884, 48.85), (1888, 47.80), (1892, 46.02), (1896.0, 51.02), (1900, 51.64), (1904, 56.42), (1908, 51.57), (1912, 41.84), (1916, 49.24), (1920, 60.32), (1924, 54.04), (1928, 58.21), ] # Lost percentage = 100-Won percentage full = [(t[0], t[1], 100 - t[1]) for t in percentages] data = pandas.DataFrame(full, columns=["Year", "Won", "Lost"]) layout = {"barmode": "stack"} page = """ # Bar - Stacked <|{data}|chart|type=bar|x=Year|y[1]=Won|y[2]=Lost|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import numpy import pandas from taipy.gui import Gui # Generate a random value for every hour on a given day data = {"Date": pandas.date_range("2023-01-04", periods=24, freq="H"), "Value": pandas.Series(numpy.random.randn(24))} page = """ # Basics - Timeline <|{data}|chart|x=Date|y=Value|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import random from taipy.gui import Gui # Data set made of two series of random numbers data = [{"x": [random.random() + 1 for i in range(100)]}, {"x": [random.random() + 1.1 for i in range(100)]}] options = [ # First data set displayed as semi-transparent, green bars {"opacity": 0.5, "marker": {"color": "green"}}, # Second data set displayed as semi-transparent, gray bars {"opacity": 0.5, "marker": {"color": "#888"}}, ] layout = { # Overlay the two histograms "barmode": "overlay", # Hide the legend "showlegend": False, } page = """ # Histogram - Overlay <|{data}|chart|type=histogram|options={options}|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "Day": ["Mon", "Tue", "Wed", "Thu", "Fri"], "Items": [32, 25, 86, 60, 70], "Price": [80, 50, 140, 10, 70], } options = [ # For items {"fill": "tozeroy"}, # For price # Using "tonexty" not to cover the first trace {"fill": "tonexty"}, ] page = """ # Filled Area - Overlay <|{data}|chart|mode=none|x=Day|y[1]=Items|y[2]=Price|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # x values are [-10..10] x_range = range(-10, 11) # The data set holds the _x_ series and two distinct series for _y_ data = { "x": x_range, # y1 = x*x "y1": [x * x for x in x_range], # y2 = 100-x*x "y2": [100 - x * x for x in x_range], } page = """ # Basics - Multiple traces <|{data}|chart|x=x|y[1]=y1|y[2]=y2|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- # Two data sets as a bar chart import pandas from taipy.gui import Gui # Source https://en.wikipedia.org/wiki/List_of_United_States_presidential_elections_by_popular_vote_margin percentages = [ (1852, 50.83), (1856, 45.29), (1860, 39.65), (1864, 55.03), (1868, 52.66), (1872, 55.58), (1876, 47.92), (1880, 48.31), (1884, 48.85), (1888, 47.80), (1892, 46.02), (1896.0, 51.02), (1900, 51.64), (1904, 56.42), (1908, 51.57), (1912, 41.84), (1916, 49.24), (1920, 60.32), (1924, 54.04), (1928, 58.21), ] data = pandas.DataFrame(percentages, columns=["Year", "Won"]) lost = [100 - t[1] for t in percentages] data["Lost"] = lost page = """ # Bar - Multiple <|{data}|chart|type=bar|x=Year|y[1]=Won|y[2]=Lost|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # You may need to install the yfinance package as well. # ----------------------------------------------------------------------------------------- import yfinance from taipy import Gui # Extraction of a month of stock data for AAPL using the # yfinance package (see https://pypi.org/project/yfinance/). ticker = yfinance.Ticker("AAPL") # The returned value is a Pandas DataFrame. stock = ticker.history(interval="1d", start="2018-08-01", end="2018-08-31") # Copy the DataFrame's index to a new column stock["Date"] = stock.index page = """ # Candlestick - Simple <|{stock}|chart|type=candlestick|x=Date|open=Open|close=Close|low=Low|high=High|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import random import numpy from taipy.gui import Gui # x = [0..20] x = list(range(0, 21)) data = { "x": x, # A list of random values within [1, 10] "y": [random.uniform(1, 10) for _ in x], } layout = { # Force the Box select tool "dragmode": "select", # Remove all margins around the plot "margin": {"l": 0, "r": 0, "b": 0, "t": 0}, } config = { # Hide Plotly's mode bar "displayModeBar": False } selected_indices = [] mean_value = 0.0 def on_change(state, var, val): if var == "selected_indices": state.mean_value = numpy.mean([data["y"][idx] for idx in val]) if len(val) else 0 page = """ # Advanced - Selection ## Mean of <|{len(selected_indices)}|raw|> selected points: <|{mean_value}|format=%.2f|raw|> <|{data}|chart|selected={selected_indices}|layout={layout}|plot_config={config}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import math import random from taipy.gui import Gui # Number of samples max_x = 20 # x values: [0..max_x-1] x = range(0, max_x) # Generate random sampling error margins error_ranges = [random.uniform(0, 5) for _ in x] # Compute a perfect sine wave perfect_y = [10 * math.sin(4 * math.pi * i / max_x) for i in x] # Compute a sine wave impacted by the sampling error # The error is between ±error_ranges[x]/2 y = [perfect_y[i] + random.uniform(-error_ranges[i] / 2, error_ranges[i] / 2) for i in x] # The chart data is made of the three series data = { "x": x, "y1": y, "y2": perfect_y, } options = { # Create the error bar information: "error_y": {"type": "data", "array": error_ranges} } page = """ # Error bars - Simple <|{data}|chart|x=x|y[1]=y1|y[2]=y2|options[1]={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "Day": ["Mon", "Tue", "Wed", "Thu", "Fri"], "Items": [32, 25, 86, 60, 70], } options = { # Fill to x axis "fill": "tozeroy" } page = """ # Filled Area - Simple <|{data}|chart|x=Day|y=Items|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import datetime import dateutil.relativedelta from taipy.gui import Gui # Data is collected from January 1st, 2010, every month start_date = datetime.datetime(year=2010, month=1, day=1) period = dateutil.relativedelta.relativedelta(months=1) # Data # All arrays have the same size (the number of months to track) prices = { # Data for apples "apples": [2.48, 2.47, 2.5, 2.47, 2.46, 2.38, 2.31, 2.25, 2.39, 2.41, 2.59, 2.61], "apples_low": [1.58, 1.58, 1.59, 1.64, 1.79, 1.54, 1.53, 1.61, 1.65, 2.02, 1.92, 1.54], "apples_high": [3.38, 3.32, 2.63, 2.82, 2.58, 2.53, 3.27, 3.15, 3.44, 3.42, 3.08, 2.86], "bananas": [2.94, 2.50, 2.39, 2.77, 2.43, 2.32, 2.37, 1.90, 2.31, 2.71, 3.38, 1.92], "bananas_low": [2.12, 1.90, 1.69, 2.44, 1.58, 1.81, 1.44, 1.00, 1.59, 1.74, 2.78, 0.96], "bananas_high": [3.32, 2.70, 3.12, 3.25, 3.00, 2.63, 2.54, 2.37, 2.97, 3.69, 4.36, 2.95], "cherries": [6.18, None, None, None, 3.69, 2.46, 2.31, 2.57, None, None, 6.50, 4.38], "cherries_high": [7.00, None, None, None, 8.50, 6.27, 5.61, 4.36, None, None, 8.00, 7.23], "cherries_low": [3.55, None, None, None, 1.20, 0.87, 1.08, 1.50, None, None, 5.00, 4.20], } # Create monthly time series months = [start_date + n * period for n in range(0, len(prices["apples"]))] data = [ # Raw data {"Months": months, "apples": prices["apples"], "bananas": prices["bananas"], "cherries": prices["cherries"]}, # Range data (twice as many values) { "Months2": months + list(reversed(months)), "apples": prices["apples_high"] + list(reversed(prices["apples_low"])), "bananas": prices["bananas_high"] + list(reversed(prices["bananas_low"])), "cherries": prices["cherries_high"] + list(reversed(prices["cherries_low"])), }, ] properties = { # First trace: reference for Apples "x[1]": "0/Months", "y[1]": "0/apples", "color[1]": "rgb(0,200,80)", # Hide line "mode[1]": "markers", # Show in the legend "name[1]": "Apples", # Second trace: reference for Bananas "x[2]": "0/Months", "y[2]": "0/bananas", "color[2]": "rgb(0,100,240)", # Hide line "mode[2]": "markers", # Show in the legend "name[2]": "Bananas", # Third trace: reference for Cherries "x[3]": "0/Months", "y[3]": "0/cherries", "color[3]": "rgb(240,60,60)", # Hide line "mode[3]": "markers", # Show in the legend "name[3]": "Cherries", # Fourth trace: range for Apples "x[4]": "1/Months2", "y[4]": "1/apples", "options[4]": { "fill": "tozerox", "showlegend": False, "fillcolor": "rgba(0,100,80,0.4)", }, # No surrounding stroke "color[4]": "transparent", # Fifth trace: range for Bananas "x[5]": "1/Months2", "y[5]": "1/bananas", "options[5]": {"fill": "tozerox", "showlegend": False, "fillcolor": "rgba(0,180,250,0.4)"}, # No surrounding stroke "color[5]": "transparent", # Sixth trace: range for Cherries "x[6]": "1/Months2", "y[6]": "1/cherries", "options[6]": { "fill": "tozerox", "showlegend": False, "fillcolor": "rgba(230,100,120,0.4)", }, # No surrounding stroke "color[6]": "transparent", } page = """ # Continuous Error - Multiple traces <|{data}|chart|properties={properties}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import random from taipy.gui import Gui # Number of samples n_samples = 10 # y values: [0..n_samples-1] y = range(0, n_samples) data = { # The x series is made of random numbers between 1 and 10 "x": [random.uniform(1, 10) for i in y], "y": y, } options = { "error_x": { "type": "data", # Allows for a 'plus' and a 'minus' error data "symmetric": False, # The 'plus' error data is a series of random numbers "array": [random.uniform(0, 5) for i in y], # The 'minus' error data is a series of random numbers "arrayminus": [random.uniform(0, 2) for i in y], # Color of the error bar "color": "red", } } page = """ # Error bars - Asymmetric <|{data}|chart|type=bar|x=x|y=y|orientation=h|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import math from taipy.gui import Gui # One data point for each degree theta = range(0, 360) # Parametric equation that draws a shape (source Wolfram Mathworld) def draw_heart(angle): a = math.radians(angle) sa = math.sin(a) return 2 - 2 * sa + sa * (math.sqrt(math.fabs(math.cos(a))) / (sa + 1.4)) data = { # Create the heart shape "r": [draw_heart(angle) for angle in theta], "theta": theta, } page = """ # Polar - Simple <|{data}|chart|type=scatterpolar|mode=lines|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # List of countries, used as labels in the pie charts countries = ["US", "China", "European Union", "Russian Federation", "Brazil", "India", "Rest of World"] data = [ { # Values for GHG Emissions "values": [16, 15, 12, 6, 5, 4, 42], "labels": countries, }, { # Values for CO2 Emissions "values": [27, 11, 25, 8, 1, 3, 25], "labels": countries, }, ] options = [ # First pie chart { # Show label value on hover "hoverinfo": "label", # Leave a hole in the middle of the chart "hole": 0.4, # Place the trace on the left side "domain": {"column": 0}, }, # Second pie chart { # Show label value on hover "hoverinfo": "label", # Leave a hole in the middle of the chart "hole": 0.4, # Place the trace on the right side "domain": {"column": 1}, }, ] layout = { # Chart title "title": "Global Emissions 1990-2011", # Show traces in a 1x2 grid "grid": {"rows": 1, "columns": 2}, "annotations": [ # Annotation for the first trace { "text": "GHG", "font": {"size": 20}, # Hide annotation arrow "showarrow": False, # Move to the center of the trace "x": 0.18, "y": 0.5, }, # Annotation for the second trace { "text": "CO2", "font": {"size": 20}, "showarrow": False, # Move to the center of the trace "x": 0.81, "y": 0.5, }, ], "showlegend": False, } page = """ # Pie - Multiple <|{data}|chart|type=pie|x[1]=0/values|x[2]=1/values|options={options}|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # The first data set uses the x interval [-10..10], # with one point at every other unit x1_range = [x * 2 for x in range(-5, 6)] # The second data set uses the x interval [-4..4], # with ten point between every unit x2_range = [x / 10 for x in range(-40, 41)] # Definition of the two data sets data = [ # Coarse data set {"x": x1_range, "Coarse": [x * x for x in x1_range]}, # Fine data set {"x": x2_range, "Fine": [x * x for x in x2_range]}, ] page = """ # Advanced - Unbalanced data sets <|{data}|chart|x[1]=0/x|y[1]=0/Coarse|x[2]=1/x|y[2]=1/Fine|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Flight start and end locations data = { # Hartsfield-Jackson Atlanta International Airport # to # Aéroport de Paris-Charles de Gaulle "lat": [33.64, 49.01], "lon": [-84.44, 2.55], } layout = { # Chart title "title": "ATL to CDG", # Hide legend "showlegend": False, # Focus on relevant area "geo": { "resolution": 50, "showland": True, "showocean": True, "landcolor": "4a4", "oceancolor": "77d", "lataxis": {"range": [20, 60]}, "lonaxis": {"range": [-100, 20]}, }, } # Flight displayed as a thick, red plot line = {"width": 5, "color": "red"} page = """ # Maps - Simple <|{data}|chart|type=scattergeo|mode=lines|lat=lat|lon=lon|line={line}|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import random from taipy.gui import Gui # Random data set data = {"Count": [random.random() for i in range(100)]} page = """ # Histograms - Horizontal <|{data}|chart|type=histogram|y=Count|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = [ { "x": [1, 2, 3, 4], "y": [10, 11, 12, 13], }, { "x": [1, 2, 3, 4], "y": [11, 12, 13, 14], }, { "x": [1, 2, 3, 4], "y": [12, 13, 14, 15], }, ] options = [ # First data set is represented by increasingly large # disks, getting more and more opaque {"marker": {"color": "red", "size": [12, 22, 32, 42], "opacity": [0.2, 0.5, 0.7, 1]}}, # Second data set is represented with a different symbol # for each data point { "marker": {"color": "blue", "size": 18, "symbol": ["circle", "square", "diamond", "cross"]}, }, # Third data set is represented with green disks surrounded # by a red circle that becomes thicker and thicker { "marker": {"color": "green", "size": 20, "line": {"color": "red", "width": [2, 4, 6, 8]}}, }, ] markers = [ # First data set is represented by increasingly large # disks, getting more and more opaque {"color": "red", "size": [12, 22, 32, 42], "opacity": [0.2, 0.5, 0.7, 1]}, # Second data set is represented with a different symbol # for each data point {"color": "blue", "size": 18, "symbol": ["circle", "square", "diamond", "cross"]}, # Third data set is represented with green disks surrounded # by a red circle that becomes thicker and thicker {"color": "green", "size": 20, "line": {"color": "red", "width": [2, 4, 6, 8]}}, ] layout = { # Hide the chart legend "showlegend": False, # Remove all ticks from the x axis "xaxis": {"showticklabels": False}, # Remove all ticks from the y axis "yaxis": {"showticklabels": False}, } page = """ ## Scatter - Customize markers <|{data}|chart|mode=markers|layout={layout}|marker={markers}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "Month": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], "Milk": [80, 85, 95, 120, 140, 130, 145, 150, 120, 100, 90, 110], "Bread": [100, 90, 85, 90, 100, 110, 105, 95, 100, 110, 120, 125], "Apples": [50, 65, 70, 65, 70, 75, 85, 70, 60, 65, 70, 80], } # Name of the three sets to trace items = ["Milk", "Bread", "Apples"] options = { # Group all traces in the same stack group "stackgroup": "first_group" } page = """ # Filled Area - Stacked <|{data}|chart|mode=none|x=Month|y={items}|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Data set data = [ { # The quarterly periods are grouped by year "Period": [["Carry", "Q1", "Q2", "Q3", "Q4", "Current"], ["N-1", "N", "N", "N", "N", "N+1"]] }, { "Cash Flow": [25, -17, 12, 18, -8, None], "Measure": ["absolute", "relative", "relative", "relative", "relative", "total"], }, ] page = """ # Waterfall - Period levels <|{data}|chart|type=waterfall|x=0/Period|y=1/Cash Flow|measure=1/Measure|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Major countries and their surface (in km2), for every continent # Source: https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_area continents = { "Africa": [ {"name": "Algeria", "surface": 2381741}, {"name": "Dem. Rep. Congo", "surface": 2344858}, {"name": "Sudan", "surface": 1886068}, {"name": "Libya", "surface": 1759540}, {"name": "Chad", "surface": 1284000}, ], "Asia": [ {"name": "Russia-Asia", "surface": 17098246}, {"name": "China", "surface": 9596961}, {"name": "India", "surface": 3287263}, {"name": "Kazakhstan", "surface": 2724900}, {"name": "Saudi Arabia", "surface": 2149690}, ], "Europe": [ {"name": "Russia-Eur", "surface": 3972400}, {"name": "Ukraine", "surface": 603628}, {"name": "France", "surface": 551695}, {"name": "Spain", "surface": 498980}, {"name": "Sweden", "surface": 450295}, ], "Americas": [ {"name": "Canada", "surface": 9984670}, {"name": "U.S.A.", "surface": 9833517}, {"name": "Brazil", "surface": 8515767}, {"name": "Argentina", "surface": 2780400}, {"name": "Mexico", "surface": 1964375}, ], "Oceania": [ {"name": "Australia", "surface": 7692024}, {"name": "Papua New Guinea", "surface": 462840}, {"name": "New Zealand", "surface": 270467}, {"name": "Solomon Islands", "surface": 28896}, {"name": "Fiji", "surface": 18274}, ], "Antarctica": [{"name": "Whole", "surface": 14200000}], } name = [] surface = [] continent = [] for continent_name, countries in continents.items(): # Create continent in root rectangle name.append(continent_name) surface.append(0) continent.append("") # Create countries in that continent rectangle for country in countries: name.append(country["name"]) surface.append(country["surface"]) continent.append(continent_name) data = {"names": name, "surfaces": surface, "continent": continent} page = """ # TreeMap - Hierarchical values <|{data}|chart|type=treemap|labels=names|values=surfaces|parents=continent|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import datetime from taipy.gui import Gui # Retrieved history: # (Open, Close, Low, High) stock_history = [ (311.05, 311.00, 310.75, 311.33), (308.53, 308.31, 307.72, 309.00), (307.35, 306.24, 306.12, 307.46), (306.35, 304.90, 304.34, 310.10), (304.90, 302.99, 302.27, 307.00), (303.03, 301.66, 301.20, 303.25), (301.61, 299.58, 299.50, 301.89), (299.58, 297.95, 297.80, 300.06), (297.95, 299.03, 297.14, 299.67), (299.03, 301.87, 296.71, 301.89), (301.89, 299.40, 298.73, 302.93), (299.50, 299.35, 298.83, 299.50), (299.35, 299.20, 299.19, 299.68), (299.42, 300.50, 299.42, 300.50), (300.70, 300.65, 300.32, 300.75), (300.65, 299.91, 299.91, 300.76), ] start_date = datetime.datetime(year=2022, month=10, day=21) period = datetime.timedelta(seconds=4 * 60 * 60) # 4 hours data = { # Compute date series "Date": [start_date + n * period for n in range(0, len(stock_history))], # Extract open values "Open": [v[0] for v in stock_history], # Extract close values "Close": [v[1] for v in stock_history], # Extract low values "Low": [v[2] for v in stock_history], # Extract high values "High": [v[3] for v in stock_history], } md = """ # Candlestick - Timeline <|{data}|chart|type=candlestick|x=Date|open=Open|close=Close|low=Low|high=High|> """ Gui(md).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "John_us": [500, 450, 340, 230, 220, 110], "John_eu": [600, 500, 400, 300, 200, 100], "Robert_us": [510, 480, 440, 330, 220, 100], "Robert_eu": [360, 250, 240, 130, 120, 60], } # Values for each trace values = ["John_us", "John_eu", "Robert_us", "Robert_eu"] options = [ # For John/US { "scalegroup": "first", "textinfo": "value", "title": { # "position": "top", "text": "John in the U.S." }, # Lower-left corner "domain": {"x": [0, 0.5], "y": [0, 0.5]}, }, # For John/EU { "scalegroup": "first", "textinfo": "value", "title": { # "position": "top", "text": "John in the E.U." }, # Upper-left corner "domain": {"x": [0, 0.5], "y": [0.55, 1]}, }, # For Robert/US { "scalegroup": "second", "textinfo": "value", "title": { # "position": "top", "text": "Robert in the U.S." }, # Lower-right corner "domain": {"x": [0.51, 1], "y": [0, 0.5]}, }, # For Robert/EU { "scalegroup": "second", "textinfo": "value", "title": { # "position": "top", "text": "Robert in the E.U." }, # Upper-right corner "domain": {"x": [0.51, 1], "y": [0.51, 1]}, }, ] layout = { "title": "Sales per Salesman per Region", "showlegend": False, # Draw frames around each trace "shapes": [ {"x0": 0, "x1": 0.5, "y0": 0, "y1": 0.5}, {"x0": 0, "x1": 0.5, "y0": 0.52, "y1": 1}, {"x0": 0.52, "x1": 1, "y0": 0, "y1": 0.5}, {"x0": 0.52, "x1": 1, "y0": 0.52, "y1": 1}, ], } page = """ # Funnel Area - Multiple Charts <|{data}|chart|type=funnelarea|values={values}|options={options}|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import math from taipy.gui import Gui # One data point for each degree theta = range(0, 360) # Parametric equation that draws a shape (source Wolfram Mathworld) def draw_heart(angle): a = math.radians(angle) sa = math.sin(a) return 2 - 2 * sa + sa * (math.sqrt(math.fabs(math.cos(a))) / (sa + 1.4)) data = { # Create the heart shape "r": [draw_heart(angle) for angle in theta], "theta": theta, } options = {"fill": "toself"} layout = { # Hide the legend "showlegend": False, "polar": { # Hide the angular axis "angularaxis": {"visible": False}, # Hide the radial axis "radialaxis": {"visible": False}, }, } page = """ # Polar - Area <|{data}|chart|type=scatterpolar|mode=none|layout={layout}|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Partial family tree of the British House of Windsor # Source: https://en.wikipedia.org/wiki/Family_tree_of_the_British_royal_family tree = { "name": [ "Queen Victoria", "Princess Victoria", "Edward VII", "Alice", "Alfred", "Wilhelm II", "Albert Victor", "George V", "Louise", "Ernest Louis", "Alfred (2)", "Marie", "Victoria Melita", "Edward VIII", "George VI", "Mary", "Elizabeth II", "Margaret", "Charles III", "Anne", "Andrew", ], "parent": [ "", "Queen Victoria", "Queen Victoria", "Queen Victoria", "Queen Victoria", "Princess Victoria", "Edward VII", "Edward VII", "Edward VII", "Alice", "Alfred", "Alfred", "Alfred", "George V", "George V", "George V", "George VI", "George VI", "Elizabeth II", "Elizabeth II", "Elizabeth II", ], } page = """ # TreeMap - Hierarchical <|{tree}|chart|type=treemap|labels=name|parents=parent|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # You may need to install the scikit-learn package as well. # ----------------------------------------------------------------------------------------- import numpy as np import pandas as pd from sklearn.datasets import make_classification from taipy.gui import Gui # Let scikit-learn generate a random 2-class classification problem n_samples = 100 features, label = make_classification(n_samples=n_samples, n_features=2, n_informative=2, n_redundant=0) random_data = pd.DataFrame({"x": features[:, 0], "y": features[:, 1], "label": label}) data_x = random_data["x"] class_A = [random_data.loc[i, "y"] if random_data.loc[i, "label"] == 0 else np.nan for i in range(n_samples)] class_B = [random_data.loc[i, "y"] if random_data.loc[i, "label"] == 1 else np.nan for i in range(n_samples)] data = {"x": random_data["x"], "Class A": class_A, "Class B": class_B} marker_A = {"symbol": "circle-open", "size": 16} marker_B = {"symbol": "triangle-up-dot", "size": 20, "opacity": 0.7} page = """ # Scatter - Styling <|{data}|chart|mode=markers|x=x|y[1]=Class A|y[2]=Class B|width=60%|marker[1]={marker_A}|marker[2]={marker_B}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "Temperatures": [ [17.2, 27.4, 28.6, 21.5], [5.6, 15.1, 20.2, 8.1], [26.6, 22.8, 21.8, 24.0], [22.3, 15.5, 13.4, 19.6], ], "Cities": ["Hanoi", "Paris", "Rio", "Sydney"], "Seasons": ["Winter", "Spring", "Summer", "Autumn"], } options = {"colorscale": "Portland"} page = """ # Heatmap - Colorscale <|{data}|chart|type=heatmap|z=Temperatures|x=Seasons|y=Cities|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui layout = { "xaxis": { # Force the title of the x axis "title": "Values for x" } } page = """ # Basics - Title <|{[x*x for x in range(0, 11)]}|chart|title=Plotting x squared|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Data set: the first 10 elements of the Fibonacci sequence n_numbers = 10 fibonacci = [0, 1] for i in range(2, n_numbers): fibonacci.append(fibonacci[i - 1] + fibonacci[i - 2]) data = {"index": [i for i in range(1, n_numbers + 1)], "fibonacci": fibonacci} page = """ # TreeMap - Simple <|{data}|chart|type=treemap|labels=index|values=fibonacci|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy import Gui # The chart control's data is defined as inline # code. page = """ # Basics - Simple line <|{[x*x for x in range(0, 11)]}|chart|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import random from taipy import Gui # Random data set data = [random.gauss(0, 5) for i in range(1000)] page = """ # Histogram - Simple <|{data}|chart|type=histogram|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import pandas from taipy.gui import Gui # Source https://en.wikipedia.org/wiki/List_of_United_States_presidential_elections_by_popular_vote_margin percentages = [ (1852, 50.83), (1856, 45.29), (1860, 39.65), (1864, 55.03), (1868, 52.66), (1872, 55.58), (1876, 47.92), (1880, 48.31), (1884, 48.85), (1888, 47.80), (1892, 46.02), (1896.0, 51.02), (1900, 51.64), (1904, 56.42), (1908, 51.57), (1912, 41.84), (1916, 49.24), (1920, 60.32), (1924, 54.04), (1928, 58.21), (1932, 57.41), (1936, 60.80), (1940, 54.74), (1944, 53.39), (1948, 49.55), (1952, 55.18), (1956, 57.37), (1960, 49.72), (1964, 61.05), (1968, 43.42), (1972, 60.67), (1976, 50.08), (1980, 50.75), (1984, 58.77), (1988, 53.37), (1992, 43.01), (1996, 49.23), (2000, 47.87), (2004, 50.73), (2008, 52.93), (2012, 51.06), (2016, 46.09), (2020, 51.31), ] data = pandas.DataFrame(percentages, columns=["Year", "%"]) page = """ # Bar - Simple <|{data}|chart|type=bar|x=Year|y=%|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import random from taipy.gui import Gui # Random set of 100 samples samples = {"x": [random.gauss() for i in range(100)]} # Use the same data for both traces data = [samples, samples] options = [ # First data set displayed as green-ish, and 5 bins {"marker": {"color": "#4A4"}, "nbinsx": 5}, # Second data set displayed as red-ish, and 25 bins {"marker": {"color": "#A33"}, "nbinsx": 25}, ] layout = { # Overlay the two histograms "barmode": "overlay", # Hide the legend "showlegend": False, } page = """ # Histogram - NBins <|{data}|chart|type=histogram|options={options}|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Data set data = {"Opps": ["Hot leads", "Doc sent", "Quote", "Closed Won"], "Visits": [316, 238, 125, 83]} page = """ # Funnel Chart - Simple <|{data}|chart|type=funnel|x=Visits|y=Opps|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = [ { "Temperatures": [ [17.2, 27.4, 28.6, 21.5], [5.6, 15.1, 20.2, 8.1], [26.6, 22.8, 21.8, 24.0], [22.3, 15.5, 13.4, 19.6], [3.9, 18.9, 25.7, 9.8], ], "Cities": ["Hanoi", "Paris", "Rio", "Sydney", "Washington"], }, {"Seasons": ["Winter", "Spring", "Summer", "Autumn"]}, ] page = """ # Heatmap - Unbalanced <|{data}|chart|type=heatmap|z=0/Temperatures|x=1/Seasons|y=0/Cities|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Sample small plot definition trace = { "r": [1, 2, 3, 4, 1], "theta": [0, 40, 80, 120, 160], } # The same data is used in both traces data = [trace, trace] # Naming the subplot is mandatory to get them both in # the same chart options = [ { "subplot": "polar", }, {"subplot": "polar2"}, ] layout = { # Hide the legend "showlegend": False, # Restrict the angular values for second trace "polar2": {"sector": [30, 130]}, } md = """ # Polar - Sectors <|{data}|chart|type=scatterpolar|layout={layout}|options={options}|> """ Gui(md).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # You may need to install the yfinance package as well. # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "x": [1, 2, 3], "y": [1, 2, 3], "Colors": ["blue", "green", "red"], "Sizes": [20, 40, 30], "Opacities": [1, 0.4, 1], } marker = {"color": "Colors", "size": "Sizes", "opacity": "Opacities"} page = """ # Bubble - Simple <|{data}|chart|mode=markers|x=x|y=y|marker={marker}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Source: www.statista.com (Most used programming languages in 2022) data = { # List of programming languages "Language": ["JavaScript", "HTML/CSS", "SQL", "Python", "Typescript", "Java", "Bash/Shell"], # Percentage of usage, per language "%": [65.36, 55.08, 49.43, 48.07, 34.83, 33.27, 29.07], } # Close the shape for a nice-looking stroke # If the first point is *not* appended to the end of the list, # then the shape does not look as it is closed. data["%"].append(data["%"][0]) data["Language"].append(data["Language"][0]) layout = { "polar": { "radialaxis": { # Force the radial range to 0-100 "range": [0, 100], } }, # Hide legend "showlegend": False, } options = { # Fill the trace "fill": "toself" } md = """ # Radar - Simple <|{data}|chart|type=scatterpolar|r=%|theta=Language|options={options}|layout={layout}|> """ Gui(md).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Initial data set. y = count_of(x) samples = {"x": ["Apples", "Apples", "Apples", "Oranges", "Bananas", "Oranges"], "y": [5, 10, 3, 8, 5, 2]} # Create a data set array to allow for two traces data = [samples, samples] # Gather those settings in a single dictionary properties = { # 'x' of the first trace is the 'x' data from the first element of data "x[1]": "0/x", # 'y' of the first trace is the 'y' data from the first element of data "y[1]": "0/y", # 'x' of the second trace is the 'x' data from the second element of data "x[2]": "1/x", # 'y' of the second trace is the 'y' data from the second element of data "y[2]": "1/y", # Data set colors "color": ["#cd5c5c", "#505070"], # Data set names (for the legend) "name": ["Count", "Sum"], # Configure the binning functions "options": [ # First trace: count the bins {"histfunc": "count"}, # Second trace: sum the bin occurences {"histfunc": "sum"}, ], # Set x axis name "layout": {"xaxis": {"title": "Fruit"}}, } page = """ # Histogram - Binning function <|{data}|chart|type=histogram|properties={properties}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Skill categories skills = ["HTML", "CSS", "Java", "Python", "PHP", "JavaScript", "Photoshop"] data = [ # Proportion of skills used for Backend development {"Backend": [10, 10, 80, 70, 90, 30, 0], "Skills": skills}, # Proportion of skills used for Frontend development {"Frontend": [90, 90, 0, 10, 20, 80, 60], "Skills": skills}, ] # Append first elements to all arrays for a nice stroke skills.append(skills[0]) data[0]["Backend"].append(data[0]["Backend"][0]) data[1]["Frontend"].append(data[1]["Frontend"][0]) layout = { # Force the radial axis displayed range "polar": {"radialaxis": {"range": [0, 100]}} } # Fill the trace options = {"fill": "toself"} # Reflected in the legend names = ["Backend", "Frontend"] # To shorten the chart control definition r = ["0/Backend", "1/Frontend"] theta = ["0/Skills", "1/Skills"] page = """ # Radar - Multiple <|{data}|chart|type=scatterpolar|name={names}|r={r}|theta={theta}|options={options}|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # x values are [-10..10] x_range = range(-10, 11) # The data set holds the _x_ series and two distinct series for _y_ data = { "x": x_range, # y1 = x*x "y1": [x * x for x in x_range], # y2 = 2-x*x/50 "y2": [(100 - x * x) / 50 for x in x_range], } layout = { "yaxis2": { # Second axis overlays with the first y axis "overlaying": "y", # Place the second axis on the right "side": "right", # and give it a title "title": "Second y axis", }, "legend": { # Place the legend above chart "yanchor": "bottom" }, } page = """ # Basics - Multiple axis Shared axis: <|{data}|chart|x=x|y[1]=y1|y[2]=y2|height=300px|> With two axis: <|{data}|chart|x=x|y[1]=y1|y[2]=y2|yaxis[2]=y2|layout={layout}|height=300px|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Source https://www.fao.org/faostat/en/#data/SDGB data = { "Country": [ "Rest of the world", "Russian Federation", "Brazil", "Canada", "United States of America", "China", "Australia", "Democratic Republic of the Congo", "Indonesia", "Peru", ], "Area": [1445674.66, 815312, 496620, 346928, 309795, 219978, 134005, 126155, 92133.2, 72330.4], } page = """ # Pie - Simple <|{data}|chart|type=pie|values=Area|label=Country|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # You may need to install the scikit-learn package as well. # ----------------------------------------------------------------------------------------- from os.path import exists from sklearn.datasets import make_regression from sklearn.linear_model import LinearRegression from taipy.gui import Gui # Let scikit-learn generate a random regression problem n_samples = 300 X, y, coef = make_regression(n_samples=n_samples, n_features=1, n_informative=1, n_targets=1, noise=25, coef=True) model = LinearRegression().fit(X, y) x_data = X.flatten() y_data = y.flatten() predict = model.predict(X) data = {"x": x_data, "y": y_data, "Regression": predict} page = """ # Scatter - Regression <|{data}|chart|x=x|y[1]=y|mode[1]=markers|y[2]=Regression|mode[2]=line|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "x": [1, 2, 3], "y": [1, 2, 3], "Texts": ["Blue<br>Small", "Green<br>Medium", "Red<br>Large"], "Sizes": [60, 80, 100], "Colors": [ "rgb(93, 164, 214)", "rgb(44, 160, 101)", "rgb(255, 65, 54)", ], } marker = {"size": "Sizes", "color": "Colors"} page = """ # Bubble - Hover text <|{data}|chart|mode=markers|x=x|y=y|marker={marker}|text=Texts|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "Temperatures": [ [17.2, 27.4, 28.6, 21.5], [5.6, 15.1, 20.2, 8.1], [26.6, 22.8, 21.8, 24.0], [22.3, 15.5, 13.4, 19.6], ], "Cities": ["Hanoi", "Paris", "Rio", "Sydney"], "Seasons": ["Winter", "Spring", "Summer", "Autumn"], } layout = { # This array contains the information we want to display in the cells # These are filled later "annotations": [], # No ticks on the x axis, show labels on top the of the chart "xaxis": {"ticks": "", "side": "top"}, # No ticks on the y axis # Add a space character for a small margin with the text "yaxis": {"ticks": "", "ticksuffix": " "}, } seasons = data["Seasons"] cities = data["Cities"] # Iterate over all cities for city in range(len(cities)): # Iterate over all seasons for season in range(len(seasons)): temperature = data["Temperatures"][city][season] # Create the annotation annotation = { # The name of the season "x": seasons[season], # The name of the city "y": cities[city], # The temperature, as a formatted string "text": f"{temperature}\N{DEGREE SIGN}C", # Change the text color depending on the temperature # so it results in a better contrast "font": {"color": "white" if temperature < 14 else "black"}, # Remove the annotation arrow "showarrow": False, } # Add the annotation to the layout's annotations array layout["annotations"].append(annotation) page = """ ## Heatmap - Annotated <|{data}|chart|type=heatmap|z=Temperatures|x=Seasons|y=Cities|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # Function to plot: x^3/3 - x def f(x): return x * x * x / 3 - x # x values: [-2.2, ..., 2.2] x = [(x - 10) / 4.5 for x in range(0, 21)] data = { "x": x, # y: [f(-2.2), ..., f(2.2)] "y": [f(x) for x in x], } layout = { # Chart title "title": "Local extrema", "annotations": [ # Annotation for local maximum (x = -1) {"text": "Local <b>max</b>", "font": {"size": 20}, "x": -1, "y": f(-1)}, # Annotation for local minimum (x = 1) {"text": "Local <b>min</b>", "font": {"size": 20}, "x": 1, "y": f(1), "xanchor": "left"}, ], } page = """ # Advanced - Annotations <|{data}|chart|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "Types": ["Website visit", "Downloads", "Prospects", "Invoice sent", "Closed"], "Visits_us": [13873, 10533, 5443, 2703, 908], "Visits_eu": [7063, 4533, 3443, 1003, 1208], "Visits_ap": [6873, 2533, 3443, 1703, 508], } # Columns for each trace x = ["Visits_us", "Visits_eu", "Visits_ap"] # Legend text for each trace names = ["US", "EU", "AP"] page = """ # Funnel - Multiple traces <|{data}|chart|type=funnel|x={x}|y=Types|name={names}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "Temperatures": [ [17.2, 27.4, 28.6, 21.5], [5.6, 15.1, 20.2, 8.1], [26.6, 22.8, 21.8, 24.0], [22.3, 15.5, 13.4, 19.6], ], "Cities": ["Hanoi", "Paris", "Rio", "Sydney"], "Seasons": ["Winter", "Spring", "Summer", "Autumn"], } page = """ # Heatmap - Basic <|{data}|chart|type=heatmap|z=Temperatures|x=Seasons|y=Cities|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- # Face-to-face bar charts example import numpy from taipy.gui import Gui n_years = 10 proportions_female = numpy.zeros(n_years) proportions_male = numpy.zeros(n_years) # Prepare the data set with random variations proportions_female[0] = 0.4 proportions_male[0] = proportions_female[0] * (1 + numpy.random.normal(0, 0.1)) for i in range(1, n_years): mean_i = (0.5 - proportions_female[i - 1]) / 5 new_value = proportions_female[i - 1] + numpy.random.normal(mean_i, 0.1) new_value = min(max(0, new_value), 1) proportions_female[i] = new_value proportions_male[i] = proportions_female[i] * (1 + numpy.random.normal(0, 0.1)) data = { "Hobbies": [ "Archery", "Tennis", "Football", "Basket", "Volley", "Golf", "Video-Games", "Reading", "Singing", "Music", ], "Female": proportions_female, # Negate these values so they appear to the left side "Male": -proportions_male, } properties = { # Shared y values "y": "Hobbies", # Bars for the female data set "x[1]": "Female", "color[1]": "#c26391", # Bars for the male data set "x[2]": "Male", "color[2]": "#5c91de", # Both data sets are represented with an horizontal orientation "orientation": "h", # "layout": { # This makes left and right bars aligned on the same y value "barmode": "overlay", # Set a relevant title for the x axis "xaxis": {"title": "Gender"}, # Hide the legend "showlegend": False, "margin": {"l": 100}, }, } page = """ # Bar - Facing <|{data}|chart|type=bar|properties={properties}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import random from taipy.gui import Gui # Random data set data = [random.random() for i in range(100)] # Normalize to show bin probabilities options = {"histnorm": "probability"} page = """ # Histogram - Normalized <|{data}|chart|type=histogram|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # You may need to install the scikit-learn package as well. # ----------------------------------------------------------------------------------------- import numpy import pandas from sklearn.datasets import make_classification from taipy.gui import Gui # Let scikit-learn generate a random 2-class classification problem features, label = make_classification(n_samples=1000, n_features=2, n_informative=2, n_redundant=0) random_data = pandas.DataFrame({"x": features[:, 0], "y": features[:, 1], "label": label}) data_x = random_data["x"] class_A = [random_data.loc[i, "y"] if random_data.loc[i, "label"] == 0 else numpy.nan for i in range(len(random_data))] class_B = [random_data.loc[i, "y"] if random_data.loc[i, "label"] == 1 else numpy.nan for i in range(len(random_data))] data = {"x": random_data["x"], "Class A": class_A, "Class B": class_B} page = """ # Scatter - Classification <|{data}|chart|mode=markers|x=x|y[1]=Class A|y[2]=Class B|width=60%|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from itertools import accumulate import numpy as np from taipy.gui import Gui grid_size = 10 data = [ { # z is set to: # - 0 if row+col is a multiple of 4 # - 1 if row+col is a multiple of 2 # - 0.5 otherwise "z": [ [0.0 if (row + col) % 4 == 0 else 1 if (row + col) % 2 == 0 else 0.5 for col in range(grid_size)] for row in range(grid_size) ] }, { # A series of coordinates, growing exponentially "x": [0] + list(accumulate(np.logspace(0, 1, grid_size))), # A series of coordinates, shrinking exponentially "y": [0] + list(accumulate(np.logspace(1, 0, grid_size))), }, ] # Axis template used in the layout object axis_template = { # Don't show any line or tick or label "showgrid": False, "zeroline": False, "ticks": "", "showticklabels": False, "visible": False, } layout = {"xaxis": axis_template, "yaxis": axis_template} options = { # Remove the color scale display "showscale": False } page = """ ## Heatmap - Unequal block sizes <|{data}|chart|type=heatmap|z=0/z|x=1/x|y=1/y|layout={layout}|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui # 9-hole course n_holes = 9 # Data set # Each entry holds an array of values. One for each hole, plus one for th data = { # ["Hole1", "Hole2", ..., "Hole9"] "Hole": [f"Hole{h}" for h in range(1, n_holes + 1)] + ["Score"], # Par for each hole "Par": [3, 4, 4, 5, 3, 5, 4, 5, 3] + [None], # Score for each hole "Score": [4, 4, 5, 4, 4, 5, 4, 5, 4] + [None], # Represented as relative values except for the last one "M": n_holes * ["relative"] + ["total"], } # Compute difference (Score-Par) data["Diff"] = [data["Score"][i] - data["Par"][i] for i in range(0, n_holes)] + [None] # Show positive values in red, and negative values in green options = {"decreasing": {"marker": {"color": "green"}}, "increasing": {"marker": {"color": "red"}}} page = """ # Waterfall - Styling <|{data}|chart|type=waterfall|x=Hole|y=Diff|measure=M|options={options}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import random from taipy.gui import Gui # Common axis for all data: [1..10] x = list(range(1, 11)) # Sample data samples = [5, 7, 8, 4, 5, 9, 8, 8, 6, 5] # Generate error data # Error that adds to the input data error_plus = [3 * random.random() + 0.5 for _ in x] # Error substracted from to the input data error_minus = [3 * random.random() + 0.5 for _ in x] # Upper bound (y + error_plus) error_upper = [y + e for (y, e) in zip(samples, error_plus)] # Lower bound (y - error_minus) error_lower = [y - e for (y, e) in zip(samples, error_minus)] data = [ # Trace for samples {"x": x, "y": samples}, # Trace for error range { # Roundtrip around the error bounds: onward then return "x": x + list(reversed(x)), # The two error bounds, with lower bound reversed "y": error_upper + list(reversed(error_lower)), }, ] properties = { # Error data "x[1]": "1/x", "y[1]": "1/y", "options[1]": { # Shows as filled area "fill": "toself", "fillcolor": "rgba(70,70,240,0.6)", "showlegend": False, }, # Don't show surrounding stroke "color[1]": "transparent", # Raw data (displayed on top of the error band) "x[2]": "0/x", "y[2]": "0/y", "color[2]": "rgb(140,50,50)", # Shown in the legend "name[2]": "Input", } page = """ # Continuous Error - Simple <|{data}|chart|properties={properties}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "Products": [ "Nail polish", "Eyebrow pencil", "Rouge", "Lipstick", "Eyeshadows", "Eyeliner", "Foundation", "Lip gloss", "Mascara", ], "USA": [12814, 13012, 11624, 8814, 12998, 12321, 10342, 22998, 11261], "China": [3054, 5067, 7004, 9054, 12043, 15067, 10119, 12043, 10419], "EU": [4376, 3987, 3574, 4376, 4572, 3417, 5231, 4572, 6134], "Africa": [4229, 3932, 5221, 9256, 3308, 5432, 13701, 4008, 18712], } # Order the different traces ys = ["USA", "China", "EU", "Africa"] options = [ # For the USA {"stackgroup": "one", "groupnorm": "percent"}, # For China {"stackgroup": "one"}, # For the EU {"stackgroup": "one"}, # For Africa {"stackgroup": "one"}, ] layout = { # Show all values when hovering on a data point "hovermode": "x unified" } page = """ # Filled Area - Stacked Normalized <|{data}|chart|mode=none|x=Products|y={ys}|options={options}|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # ----------------------------------------------------------------------------------------- import math from taipy.gui import Gui # One data point for each degree theta = range(0, 360) # Create a rose-like shaped radius-array def create_rose(n_petals): return [math.cos(math.radians(n_petals * angle)) for angle in theta] data = {"theta": theta, "r1": create_rose(2), "r2": create_rose(3), "r3": create_rose(4)} # We want three traces in the same chart r = ["r1", "r2", "r3"] layout = { # Hide the legend "showlegend": False, "polar": { # Hide the angular axis "angularaxis": {"visible": False}, # Hide the radial axis "radialaxis": {"visible": False}, }, } page = """ # Polar - Multiple <|{data}|chart|type=scatterpolar|mode=lines|r={r}|theta=theta|layout={layout}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # You may need to install the yfinance package as well. # ----------------------------------------------------------------------------------------- from taipy.gui import Gui data = { "x": [1, 2, 3, 4, 5], "y": [10, 7, 4, 1, 5], "Sizes": [20, 30, 40, 50, 30], "Symbols": ["circle-open", "triangle-up", "hexagram", "star-diamond", "circle-cross"], } marker = { "color": "#77A", "size": "Sizes", "symbol": "Symbols", } page = """ # Bubble - Symbols <|{data}|chart|mode=markers|x=x|y=y|marker={marker}|> """ Gui(page).run()
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # ----------------------------------------------------------------------------------------- # To execute this script, make sure that the taipy-gui package is installed in your # Python environment and run: # python <script> # You may need to install the yfinance package as well. # ----------------------------------------------------------------------------------------- import yfinance from taipy.gui import Gui # Extraction of a few days of stock historical data for AAPL using # the yfinance package (see https://pypi.org/project/yfinance/). # The returned value is a Pandas DataFrame. ticker = yfinance.Ticker("AAPL") stock = ticker.history(interval="1d", start="2018-08-18", end="2018-09-10") # Copy the DataFrame index to a new column stock["Date"] = stock.index options = { # Candlesticks that show decreasing values are orange "decreasing": {"line": {"color": "orange"}}, # Candlesticks that show decreasing values are blue "increasing": {"line": {"color": "blue"}}, } layout = { "xaxis": { # Hide the range slider "rangeslider": {"visible": False} } } page = """ # Candlestick - Styling <|{stock}|chart|type=candlestick|x=Date|open=Open|close=Close|low=Low|high=High|options={options}|layout={layout}|> """ Gui(page).run()