Solved! Somewhat. Thanks to @tcbegley from the following link.
In this case, dash-bootstrap-components
isn’t required. Achieved using buttons.
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
app = dash.Dash(__name__, static_folder="assets")
app.config["suppress_callback_exceptions"]=True
def gen_dash_dep(dep, comp_id, comp_prop):
if len(comp_prop) == 1:
comp_prop = comp_prop * len(comp_id)
return [dep(c[0], c[1]) for c in zip(comp_id, comp_prop)]
app.layout = html.Div([
html.Button("Day", id="day", disabled=True),
html.Button("Week", id="week"),
html.Button("Month", id="month")
], className="button-group", id="date-group")
@app.callback(
gen_dash_dep(Output, ["day", "week", "month"], ["disabled"]),
gen_dash_dep(Input, ["day", "week", "month"], ["n_clicks"])
)
def toggle_buttons(n_day, n_week, n_month):
ctx = dash.callback_context
if not ctx.triggered:
raise PreventUpdate
else:
button_id = ctx.triggered[0]["prop_id"].split(".")[0]
if not any([n_day, n_week, n_month]):
raise PreventUpdate
elif button_id == "day":
return True, False, False
elif button_id == "week":
return False, True, False
elif button_id == "month":
return False, False, True
if __name__ == "__main__":
app.run_server(debug=True)
Using the following CSS:
.button-group button {
border: 1px solid #ccc;
border-radius: 0px;
font: bold 11px Roboto, sans-serif;
padding: 6px 7px;
background-image: -webkit-linear-gradient(top,#fefefe,#f3f3f3);
background-image: -moz-linear-gradient(top,#fefefe,#f3f3f3);
cursor: pointer;
margin: 0px -1px 0px 0px;
border-collapse: collapse; }
.button-group button:focus {
outline:0; }
.button-group button:first-child {
border-radius: 3px 0 0 3px; }
.button-group button:last-child {
border-radius: 0 3px 3px 0; }
.button-group button:hover {
box-shadow: inset 0px 1px 2px rgba(0,0,0,.2); }
.button-group button:disabled {
color: black;
background-image: -webkit-linear-gradient(top,#eee,#e3e3e3);
background-image: -moz-linear-gradient(top, #eee,#e3e3e3);
box-shadow: inset 0px 1px 2px rgba(0,0,0,.2);
}