0% found this document useful (0 votes)
2 views2 pages

Creating a Python Menu with Plotly

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Creating a Python Menu with Plotly

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

# Menu

2. python ploty dash create modal with input from dataframe for a menu checklist
running function like Celsius temperature equation function, Fahrenheit equation
function, Reamur function using input text This modal has text status and result
calculation for each function has [Link] modal has a dash bootsatps progress
inside modal related to the proportion of progress of the temperature equation
functions in each menu checklist.
# [Link]

# [1]
import dash
import dash_bootstrap_components as dbc
from dash import dcc, html, Input, Output, State
import pandas as pd
import time

app = [Link](__name__, external_stylesheets=[[Link]])

# Sample DataFrame
data = {
'Text': ['ndvi', 'lai', 'evi', 'date', 'fig'],
'C_to_F': [0, 5, 10, 15, 20],
'F_to_C': [32, 41, 50, 59, 68],
'C_to_R': [0, 4, 7, 11, 14]
}

df = [Link](data)

[Link] = [Link]([
html.H1("Temperature Conversion Tool"),
[Link]("Open Modal", id="open-modal-button"),
[Link]([
[Link]("Conversion Progress"),
[Link]([
[Link](
id="dataframe-dropdown",
options=[{'label': item, 'value': item} for item in df['Text']],
value=df['Text'][0]
),
[Link](
id="menu-checklist",
options=[
{'label': 'Celsius to Fahrenheit', 'value': 'c_to_f'},
{'label': 'Fahrenheit to Celsius', 'value': 'f_to_c'},
{'label': 'Celsius to Reamur', 'value': 'c_to_r'}
],
value=[]
),
[Link](id="conversion-results", rows=10),
[Link](id='progress-bar', value=0, striped=True, animated=True),
]),
], id='conversion-modal', is_open=False)
])

@[Link](
Output('conversion-modal', 'is_open'),
Input('open-modal-button', 'n_clicks'),
State('conversion-modal', 'is_open')
)
def toggle_modal(n_clicks, is_open):
if n_clicks:
return not is_open
return is_open

@[Link](
Output('conversion-results', 'value'),
Output('progress-bar', 'value'),
Input('menu-checklist', 'value'),
Input('dataframe-dropdown', 'value'),
prevent_initial_call=True
)
def calculate_conversions(selected_items, selected_text):
if not selected_items:
return "No conversions selected", 0

total_checklist_items = len(df) # Total items in the checklist


current_progress = 0
results = []

for item in selected_items:


if item == 'c_to_f':
conversion_function = "Celsius to Fahrenheit"
elif item == 'f_to_c':
conversion_function = "Fahrenheit to Celsius"
elif item == 'c_to_r':
conversion_function = "Celsius to Reamur"

row = df[df['Text'] == selected_text]


[Link](2) # Simulate processing time
current_progress += 1
progress_percentage = (current_progress / 3) * 100
result = f"{conversion_function} - Processing - {progress_percentage:.2f}%
complete"
[Link](result)

return "\n".join(results), progress_percentage

if __name__ == '__main__':
app.run_server(debug=True)

#[ 2 ]

You might also like