You can create a multi-plot dashboard using the dash library by combining stockdex plotting functions with stockdex.lib.plot_multiple_categories.
Crucial Requirement: When calling any function with the plot_ prefix, you must set show_plot=False. This ensures the function returns a Plotly figure object instead of attempting to render the plot immediately in a separate browser tab. If you do not set this, your dashboard will not function correctly as the plots will be displayed in separate tabs instead of being passed to the dashboard builder.
To build the dashboard:
- Initialize a
Ticker object. - Generate a list of Plotly figures by calling various
plot_ methods on the ticker instance with show_plot=False. - Pass the ticker symbol and the list of figures to
plot_multiple_categories().
The dashboard is served by default at http://127.0.0.1:8050/.
from stockdex.ticker import Ticker
from stockdex.lib import plot_multiple_categories
ticker = Ticker(ticker="MSFT")
# Generate figures with show_plot=False to return Plotly objects
figures = [
ticker.plot_digrin_shares_outstanding(show_plot=False),
ticker.plot_digrin_price(show_plot=False),
ticker.plot_digrin_dividend(show_plot=False),
ticker.plot_digrin_assets_vs_liabilities(show_plot=False),
ticker.plot_digrin_free_cash_flow(show_plot=False),
ticker.plot_digrin_net_income(show_plot=False),
ticker.plot_digrin_cash_and_debt(show_plot=False),
ticker.plot_digrin_expenses(show_plot=False),
ticker.plot_digrin_cost_of_revenue(show_plot=False),
]
# Create the Dash app
plot_multiple_categories(ticker=ticker.ticker, figures=figures)