Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Calling the Model from button

$
0
0

Hi,

the Button is created based on the callback. now I want to open the model when I click button. the problem is the button is generated by the function which is not part of layout.
Below is the code

def GetStats(hstname):
    es = Elasticsearch(host="1.1.3.8", port="19200")
    query = {
        "query": {
	            "bool": {
		            "must": [
			            { "match": { "Hostname": hstname }}
			        ]
		        }
                },"size": 1,
			    "sort": [
				   {
				   "@timestamp": {
				   "order": "desc"
					   }
				   }
		        ]
    }
    res = es.search(index="lenel*",  body=query, size=1)
    Services = pd.json_normalize(res['hits']['hits'][0]['_source']['Services'])
    Services.rename(columns={'Name':'Service Name'},inplace=True)
    DownCount = Services['Status'].str.contains('Stopped').sum()
    if DownCount>0:
        clr = "danger"
    else:
        clr = "success"
    ServiceTable = dash_table.DataTable(
		data=Services.to_dict('records'),
		columns=[{'id': c, 'name': c} for c in Services.columns],
    ),
    card_content = [
    dbc.CardHeader(html.H5(Hostname.upper()), style={'text-align': 'center'}),
    dbc.CardBody([
            dbc.Row([dbc.Button("Service Status",id="opens" ,color = clr, className="mr-1"),
                      dbc.Modal([
                             dbc.ModalHeader("Services Status"),
                             dbc.ModalBody(ServiceTable),
	                         dbc.ModalFooter(dbc.Button("Close", id="closes", className="ml-auto"))
                         ],id="modals",size="lg")
                    ],justify='center'),
        ]),
    ]
    return (card_content)
	

app.layout = html.Div(dbc.Col([dbc.Card(id='someid', color="dark", inverse=True)],width=2))

@app.callback(Output('someid', 'children'),
              [Input('interval-component', 'n_intervals')])
def gencard(n):
    A = GetStats("hostnames")
    return A

@app.callback(
    Output("modals", "is_open"),
    [Input("opens", "n_clicks"), Input("closes", "n_clicks")],
    [State("modals", "is_open")],
)
def toggle_modal(n1, n2, is_open):
    if n1 or n2:
        return not is_open
    return is_open

Not Sure what I’m missing here…

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles