Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/doc#986 - Document best practice on main script #1

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# 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 taipy as tp
from taipy.gui import Gui

Expand All @@ -16,16 +17,14 @@
from taipy import Core
from pages import *


pages = {
"/": root_page,
"Overview": Overview,
"Analysis": Analysis,
"Predictions": Predictions
}


if __name__ == "__main__":
pages = {
"/": root_page,
"Overview": Overview,
"Analysis": Analysis,
"Predictions": Predictions
}

core = Core()
core.run()
# #############################################################################
Expand Down
25 changes: 11 additions & 14 deletions src_enterprise/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# 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 taipy as tp
from taipy.gui import Gui, notify

Expand All @@ -18,18 +19,6 @@
from taipy import Core
from pages import *


pages = {
"/": root_page,
"login": login_page,
"Overview": Overview,
"Analysis": Analysis,
"Predictions": Predictions,
"Admin": Admin,
}

current_page = "Overview"

def on_navigate(state, page):
if page not in ["login", "TaiPy_root_page"]:
state.current_page = page
Expand All @@ -41,9 +30,18 @@ def on_navigate(state, page):
else:
return page

if __name__ == "__main__":
pages = {
"/": root_page,
"login": login_page,
"Overview": Overview,
"Analysis": Analysis,
"Predictions": Predictions,
"Admin": Admin,
}

current_page = "Overview"

if __name__ == "__main__":
core = Core()
core.run()
# #############################################################################
Expand All @@ -56,7 +54,6 @@ def on_navigate(state, page):
# Comment, remove or replace the previous lines with your own use case #
# #############################################################################


gui = Gui(pages=pages)
gui.run(title="Sales Enterprise", port=2853, dark_mode=False)

118 changes: 57 additions & 61 deletions src_single_page_taipy_tech_talk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import taipy.gui.builder as tgb


data = pd.read_csv('data/modified_supermarkt_sales_plus.csv')


def create_pie_figure(data, group_by: str):
grouped_data = data.groupby(group_by)['Total'].sum().reset_index()
grouped_data['Total'] = grouped_data['Total'].round(2)
Expand Down Expand Up @@ -37,86 +34,85 @@ def create_perc_fig(df, group_column):
fig = px.bar(df, x='Month_Year', y='Percentage', color=group_column, title=f"Evolution of Sales by {group_column} over Time", labels={'Percentage': '% of Total'}, text_auto=True)
return fig

def on_selector(state):
filtered_data = state.data.loc[
state.data["City"].isin(state.city)
]

fig_map = create_sales_by_city_map(data)

fig_product_line = create_pie_figure(data, 'Product_line')
fig_city = create_pie_figure(data, 'City')
fig_customer_type = create_pie_figure(data, 'Customer_type')
state.fig_product_line_perc = create_perc_fig(filtered_data, 'Product_line')
state.fig_city_perc = create_perc_fig(filtered_data, 'City')
state.fig_gender_perc = create_perc_fig(filtered_data, 'Gender')
state.fig_customer_type_perc = create_perc_fig(filtered_data, 'Customer_type')

fig_time = create_bar_figure(data, 'Time')
fig_date = create_bar_figure(data, 'Date')
if __name__ == "__main__":
data = pd.read_csv('data/modified_supermarkt_sales_plus.csv')

fig_map = create_sales_by_city_map(data)

city = ["Bangkok", "Chiang Mai", "Vientiane", "Luang Prabang", "Yangon", "Naypyitaw"]
fig_product_line = create_pie_figure(data, 'Product_line')
fig_city = create_pie_figure(data, 'City')
fig_customer_type = create_pie_figure(data, 'Customer_type')

filtered_data = data.loc[
data["City"].isin(city)
]
fig_time = create_bar_figure(data, 'Time')
fig_date = create_bar_figure(data, 'Date')

fig_product_line_perc = create_perc_fig(filtered_data, 'Product_line')
fig_city_perc = create_perc_fig(filtered_data, 'City')
fig_gender_perc = create_perc_fig(filtered_data, 'Gender')
fig_customer_type_perc = create_perc_fig(filtered_data, 'Customer_type')

city = ["Bangkok", "Chiang Mai", "Vientiane", "Luang Prabang", "Yangon", "Naypyitaw"]

def on_selector(state):
filtered_data = state.data.loc[
state.data["City"].isin(state.city)
filtered_data = data.loc[
data["City"].isin(city)
]

state.fig_product_line_perc = create_perc_fig(filtered_data, 'Product_line')
state.fig_city_perc = create_perc_fig(filtered_data, 'City')
state.fig_gender_perc = create_perc_fig(filtered_data, 'Gender')
state.fig_customer_type_perc = create_perc_fig(filtered_data, 'Customer_type')
fig_product_line_perc = create_perc_fig(filtered_data, 'Product_line')
fig_city_perc = create_perc_fig(filtered_data, 'City')
fig_gender_perc = create_perc_fig(filtered_data, 'Gender')
fig_customer_type_perc = create_perc_fig(filtered_data, 'Customer_type')


with tgb.Page() as page:
tgb.text("# Sales Insights", mode="md")
with tgb.Page() as page:
tgb.text("# Sales Insights", mode="md")

with tgb.layout("1 1 1"):
with tgb.part():
tgb.text("## Total Sales", mode="md")
tgb.text("### {int(data['Total'].sum())}", mode="md")
with tgb.layout("1 1 1"):
with tgb.part():
tgb.text("## Total Sales", mode="md")
tgb.text("### {int(data['Total'].sum())}", mode="md")

with tgb.part():
tgb.text("## Average Sales", mode="md")
tgb.text("### {int(data['Total'].mean())}", mode="md")
with tgb.part():
tgb.text("## Average Sales", mode="md")
tgb.text("### {int(data['Total'].mean())}", mode="md")

with tgb.part():
tgb.text("## Mean Rating", mode="md")
tgb.text("### {int(data['Rating'].mean())}", mode="md")
with tgb.part():
tgb.text("## Mean Rating", mode="md")
tgb.text("### {int(data['Rating'].mean())}", mode="md")

with tgb.expandable(title="Data", expanded=False):
tgb.table("{data}")
with tgb.expandable(title="Data", expanded=False):
tgb.table("{data}")

tgb.chart(figure="{fig_map}")
tgb.chart(figure="{fig_map}")

with tgb.layout("1 1 1"):
tgb.chart(figure="{fig_product_line}")
tgb.chart(figure="{fig_city}")
tgb.chart(figure="{fig_customer_type}")

tgb.chart(figure="{fig_time}")
tgb.chart(figure="{fig_date}")
with tgb.layout("1 1 1"):
tgb.chart(figure="{fig_product_line}")
tgb.chart(figure="{fig_city}")
tgb.chart(figure="{fig_customer_type}")
tgb.chart(figure="{fig_time}")
tgb.chart(figure="{fig_date}")

tgb.text("## Analysis", mode="md")
tgb.text("## Analysis", mode="md")

tgb.selector(value="{city}", lov=["Bangkok", "Chiang Mai", "Vientiane", "Luang Prabang", "Yangon", "Naypyitaw"],
dropdown=True,
multiple=True,
label="Select cities",
class_name="fullwidth",
on_change=on_selector)
tgb.selector(value="{city}", lov=["Bangkok", "Chiang Mai", "Vientiane", "Luang Prabang", "Yangon", "Naypyitaw"],
dropdown=True,
multiple=True,
label="Select cities",
class_name="fullwidth",
on_change=on_selector)

with tgb.layout("1 1"):
tgb.chart(figure="{fig_product_line_perc}")
tgb.chart(figure="{fig_city_perc}")
tgb.chart(figure="{fig_gender_perc}")
tgb.chart(figure="{fig_customer_type_perc}")
with tgb.layout("1 1"):
tgb.chart(figure="{fig_product_line_perc}")
tgb.chart(figure="{fig_city_perc}")
tgb.chart(figure="{fig_gender_perc}")
tgb.chart(figure="{fig_customer_type_perc}")


if __name__ == "__main__":
gui = Gui(page)
gui.run(title="Sales", port=2452)