When developing an application, sometimes it is helpful to log application events and browse them as the application is being used.
dstack offers a simple way to log application events and access them from the interface.
The easiest way of logging application events is by printing them into
stdout (e.g. using
print()). Here's an example:
from datetime import datetime, timedeltaimport dstack.controls as ctrlimport dstack as dsimport plotly.graph_objects as goimport pandas_datareader.data as webdef symbols_handler(symbols: ctrl.ComboBox):print("Calling symbols_handler")symbols.data = ['FB', 'AMZN', 'AAPL', 'NFLX', 'GOOG']def get_chart(symbols: ctrl.ComboBox):print("Calling get_chart")start = datetime.today() - timedelta(days=30)end = datetime.today()df = web.DataReader(symbols.value(), 'yahoo', start, end)fig = go.Figure(data=[go.Candlestick(x=df.index, open=df['Open'], high=df['High'], low=df['Low'], close=df['Close'])])return figapp = ds.app(get_chart, symbols=ctrl.ComboBox(handler=symbols_handler, require_apply=True))result = ds.push('faang_with_logs', app)print(result.url)