Spaces:
Sleeping
Sleeping
from bokeh.plotting import figure | |
from bokeh.layouts import row | |
from bokeh.models import ColumnDataSource | |
import pandas as pd | |
import panel as pn | |
from bokeh.models import NumeralTickFormatter | |
from bokeh.models.widgets import Select | |
from bokeh.models import FactorRange | |
import panel as pn | |
taller = pd.read_excel("./taller.xlsx") | |
taller | |
taller["x"]= taller.apply(lambda row: (row["Cliente"], row["Tipo"]), axis=1 ) | |
x_range= FactorRange(*taller["x"]) | |
source = ColumnDataSource(taller) | |
options = [("total","Total") , ("porcentaje", "Porcentaje")] | |
select= Select(options=options, title="Seleccione una opcion") | |
p = figure(x_range= x_range, sizing_mode="scale_width") | |
bars= p.vbar(source=source, x="x", bottom=0, top="Reparaciones", width=0.8) | |
layout= row([select, p], sizing_mode="stretch_both") | |
def update_graph(attr, old, new): | |
global bars | |
p.renderers.remove(bars) | |
if new == "total": | |
bars= p.vbar(source=source, x="x", bottom=0, top="Reparaciones", width=0.8) | |
y_formatter= NumeralTickFormatter(format="0,0") | |
p.yaxis.formatter= y_formatter | |
elif new =="porcentaje": | |
bars= p.vbar(source=source, x="x", bottom=0, top="Porcentaje", width=0.8) | |
y_formatter= NumeralTickFormatter(format="0%") | |
p.yaxis.formatter= y_formatter | |
select.on_change("value",update_graph) | |
bokeh_panel = pn.pane.Bokeh(layout) | |
bokeh_panel.servable() |