Ejemplo n.º 1
0
    def register_app(self, theapp):
        @theapp.callback([ServersideOutput(self.main_store.id, 'data')],
                         [Trigger(self.trigger_interval.id, 'n_intervals')])
        def _update_main_store():
            print(f"EiaAccess._update_main_store")
            df = pd.read_csv(self.input_pet_file)
            return df

        @theapp.callback([
            Output(self.data_dt.id, 'data'),
            Output(self.data_dt.id, 'columns')
        ], [
            Input(self.main_store.id, 'data'),
            Input(self.num_displayable_columns.id, 'value'),
            Input(self.eia_cat_div.dropdowns_store.id, 'data')
        ])
        def _populate_data_dt(df_main_store_data, num_displayable_columns,
                              dropdowns_store):

            print(
                f"EiaAccess._populate_data_dt number of columns:{len(df_main_store_data.columns.values)}"
            )
            if dropdowns_store is None:
                columns = df_main_store_data.columns.values[:
                                                            num_displayable_columns]
            else:
                padd_name = dropdowns_store['padd_name']
                padd_location = None  #dropdowns_store['padd_location']
                padd_production_type = dropdowns_store['padd_production_type']
                padd_fuel_type = dropdowns_store['padd_fuel_type']
                gas_price_region = dropdowns_store['gas_price_region']
                gas_price_gas_type = dropdowns_store['gas_price_gas_type']
                gas_price_grade = dropdowns_store['gas_price_grade']

                df_cols = self.eia_cat_div.eia_categories.get_column_set(
                    padd_name, padd_location, padd_production_type,
                    padd_fuel_type, gas_price_region, gas_price_gas_type,
                    gas_price_grade)
                columns = list(set(['date'] + list(df_cols.col.values)))
                # make date the first column
                columns = ['date'] + [c for c in columns if c != 'date']
                columns = columns[:num_displayable_columns]

            df_ret = df_main_store_data[columns]
            ret_columns = [{'label': c, 'id': c} for c in columns]

            dict_ret = df_ret.to_dict('records')
            return dict_ret, ret_columns

        self.eia_cat_div.register_app(theapp)
        self.logger.info('registered eia_access')
Ejemplo n.º 2
0
import dash_html_components as html
from dash_extensions.enrich import Output, Dash, Trigger

app = Dash(prevent_initial_callbacks=True)
app.layout = html.Div([
    html.Button("Left", id="left"), html.Button("Right", id="right"), html.Div(id="log"),
])


@app.callback(Output("log", "children"), Trigger("left", "n_clicks"), group="lr")  # targets same output as right
def left():
    return "left"


@app.callback(Output("log", "children"), Trigger("right", "n_clicks"), group="lr")  # targets same output as left
def right():
    return "right"


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

Ejemplo n.º 3
0
#         raise PreventUpdate
#     else:

#         spec = np.roll(existing_store['spec'],-1,0)
#         spec[-1] = newLine

#         existing_store['spec'] = spec
#         existing_store['freqs'] = freqs
#         existing_store['timestamp'] = timestamp

#         return existing_store


@app.callback(
    ServersideOutput("userServerStore",
                     "data"), [Trigger("check_for_data", "n_intervals")],
    [State("spec", "relayoutData"),
     State("userServerStore", "data")],
    prevent_initial_call=True)
def update_server_store(relayoutData, userServerStore):
    existing_store = userServerStore

    latest_message = numpy_from_Redis(redis_client, 'latest')
    latest_integration = np.array(latest_message[:-1], dtype=const.DTYPE)
    latest_timestamp = latest_message[-1]

    if existing_store == None:
        existing_store = {
            'spec': start_spec,
            'freqs': start_freqs,
            'timestamp': 0.0
Ejemplo n.º 4
0
        fig.add_trace(go.Scatter(x=df.index, y=df[col]))
    return fig


def make_layout(tag):
    return [
        dcc.Graph(id=f"graph_{tag}"),
        html.Button(f"Update [{tag}]", id=f"btn_{tag}")
    ]


tags = ["default", "memoize", "prejson"]
memoize = dict(default=None, memoize=True, prejson=plotly_jsonify)
# Create dummy data.
df = pd.DataFrame(index=pd.date_range("2020-01", "2021-01", freq="H"),
                  columns=list("ABCDEFGHIJK"),
                  data=pd.np.nan)
df[:] = np.random.random(df.values.shape)
# Create example app.
app = Dash(prevent_initial_callbacks=True)
app.layout = html.Div(
    list(itertools.chain.from_iterable([make_layout(tag) for tag in tags])))
# Attach callbacks.
for t in tags:
    app.callback(Output(f"graph_{t}", "figure"),
                 Trigger(f"btn_{t}", "n_clicks"),
                 memoize=memoize[t])(make_figure)

if __name__ == '__main__':
    app.run_server(port=8877, debug=True)
import time
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
from dash_extensions.enrich import Dash, Output, Input, Trigger, ServersideOutput

app = Dash(prevent_initial_callbacks=True)
app.layout = html.Div([
    html.Button("Query data", id="btn"),
    dcc.Dropdown(id="dd"),
    dcc.Graph(id="graph"),
    dcc.Loading(dcc.Store(id='store'), fullscreen=True, type="dot")
])


@app.callback(ServersideOutput("store", "data"), Trigger("btn", "n_clicks"))
def query_data():
    time.sleep(1)
    return px.data.gapminder()  # no JSON serialization here


@app.callback(Input("store", "data"), Output("dd", "options"))
def update_dd(df):
    return [{
        "label": column,
        "value": column
    } for column in df["year"]]  # no JSON de-serialization here


@app.callback(
    Output("graph", "figure"),
Ejemplo n.º 6
0
import dash_html_components as html
from dash_extensions.enrich import Output, Dash, Trigger

app = Dash(prevent_initial_callbacks=True)
app.layout = html.Div([html.Button("Click me", id="btn"), html.Div(id="log")])


@app.callback(Output("log", "children"), Trigger("btn", "n_clicks"))
def func():  # argument is omitted from the function
    return "You clicked the button"


if __name__ == '__main__':
    app.run_server()
Ejemplo n.º 7
0
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
from dash_extensions.enrich import Dash, Output, Input, Trigger, ServersideOutput

app = Dash(prevent_initial_callbacks=True)
app.layout = html.Div([
    html.Button("Query data", id="btn"),
    dcc.Dropdown(id="dd"),
    dcc.Graph(id="graph"),
    dcc.Loading(dcc.Store(id='store'), fullscreen=True, type="dot")
])


@app.callback(ServersideOutput("store", "data"),
              Trigger("btn", "n_clicks"),
              memoize=True)
def query_data():
    time.sleep(1)
    return px.data.gapminder()


@app.callback(Input("store", "data"), Output("dd", "options"))
def update_dd(df):
    return [{"label": column, "value": column} for column in df["year"]]


@app.callback(
    Output("graph", "figure"),
    [Input("store", "data"), Input("dd", "value")])
def update_graph(df, value):
Ejemplo n.º 8
0
                'hoverinfo': 'text',
                'text': hover_text
            }],
            'layout': {
                'title': '<b>Feature Pairwise Co-occurrence</b> ',
            }
        }
    return {
        'layout': {
            'title': '<b>Feature Pairwise Co-occurrence</b>  ',
        }
    }


@app.callback(Output('scatter', 'figure'), [
    Trigger('prog-len-filter-slider', 'value'),
    Input('crossfilter-xaxis-column', 'value'),
    Input('crossfilter-yaxis-column', 'value'),
    Input('co-occurrence-graph', 'clickData'),
    Input('ori-df-store', 'data')
])
def update_two_feature_scatter_plot_using_filters(xaxis_column_index,
                                                  yaxis_column_index,
                                                  co_click_data, ori_df):
    X, y = ResultProcessing.read_dataset_X_y(ori_df)
    names = ResultProcessing.read_dataset_names(ori_df)
    ctx = dash.callback_context
    trigger_id = ctx.triggered[0]['prop_id'].split('.')[0]
    if trigger_id == 'crossfilter-xaxis-column' or trigger_id == 'crossfilter-yaxis-column':
        xaxis_column_index = int(xaxis_column_index)
        yaxis_column_index = int(yaxis_column_index)