✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Avoid an output to change (trying to avoid repeat outputs)

I want to avoid some outputs to change, I know the raise update works, but somtimes is not possible to use it.

I’m in trouble with State() modes, my app don’t work with same State() and Output() in the same callback!

In the code I want to avoid the “*” to update the output:

@app.callback(
    [Output('layer', 'data'), Output('column', 'data'), Output('state', 'data'), Output('city', 'data')],
    [Input('dropdown1', 'value'), Input('map1', 'clickData'), Input('map2', 'clickData')]
)
def input_elements(value, map1clickData, map2clickData):
    change_id = dash.callback_context.triggered[0]['prop_id']
    if 'dropdown' in change_id:
        return  *,  value,  *,  * 
    if 'map1' in change_id:
        layer = 2
        state = str(json.dumps(map1ClickData['points'][0]['location']).strip('"'))
        return layer,  *,  state,  *
    if 'map2' in change_id:
        layer = 3
        city  = str(json.dumps(map2ClickData['points'][0]['location']).strip('"'))
        return layer,  *,  *,  city

@app.callback(
    [Output('divMapa', 'children'), Output('graph1', 'figure')],
    [Input('layer', 'data'), Input('column', 'data'), Input('state', 'data'), Input('city', 'data')]
)
def output_elements(layer, column, state, city):
    change_id = dash.callback_context.triggered[0]['prop_id']
    if 'column' in change_id:
        if layer == 1:
			...do something
			return map1, graph1
        if layer == 2 or layer == 3:
			...do something
			return map2, graph1
    if 'state' in change_id:
        if layer == 1:
			...do something
			return map1, graph1
        if layer == 2 or layer == 3:
			...do something
			return map2, graph1
    if 'city' in change_id:
        if layer == 1:
			...do something
			return map1, graph1
        if layer == 2 or layer == 3:
			...do something
			return map2, graph1




If is possible to help me implement this, anyway thak you!

Got it!

For who want the solution:

# dropdown1 value
@app.callback(
	Output('column', 'data'),
	[Input('dropdown1', 'value')])
def dropdown1Update(value):
	if value is None:
		raise PreventUpdate
	else:
	    return  value

# map1 state
@app.callback(
	Output('state', 'data'),
	[Input('map1', 'clickData')])
def map1UpdateState(map1ClickData):
	if map1ClickData is None:
		raise PreventUpdate
	else:
		state = str(json.dumps(map1ClickData['points'][0]['location']).strip('"'))
		return state

# map2 city
@app.callback(
	Output('city', 'data'),
	[Input('map2', 'clickData')])
def map2UpdateCity(map2ClickData):
	if map2ClickData is None:
		raise PreventUpdate
	else:
		city = int(json.dumps(map2ClickData['points'][0]['location']).strip('"'))
		return city

# map1 and map2 clickData
@app.callback(
	Output('layer', 'data'),
	[Input('state', 'data'), Input('city', 'data')])
def map1Map2UpdateLayer(state, city):
    change_id = dash.callback_context.triggered[0]['prop_id']
    if 'state' in change_id:
        return 2
    if 'city' in change_id:
        return 3


@app.callback(
	Output('divGrafico2', 'children'),
	[Input('column', 'data'), Input('layer', 'data'), Input('state', 'data'), Input('city', 'data')])
def teste(column, layer, state, city):
	change_id = dash.callback_context.triggered[0]['prop_id']
	return f"change_id: {change_id}\nlayer: {layer}\nstate: {state}\nibge: {city}\ncoluna: {column}"



# Storage elements
@app.callback(
	[Output('divMapa', 'children'), Output('graph1', 'figure')],
	[Input('column', 'data'), Input('layer', 'data'), Input('state', 'data'), Input('city', 'data')])
def storageInputElements(column, layer, state, city):
	change_id = dash.callback_context.triggered[0]['prop_id']
	if 'column' in change_id:
		if layer == 1:
			map1 = dcc.Graph(
				id        = 'map1',
				className = 'map1',
				figure    = map1_figure(coluna = column),
			)
			graph1 = graph1_figure(coluna = column)
			return map1, graph1
		if layer == 2:
			map2 = dcc.Graph(
				id        = 'map2',
				className = 'map2',
				figure    = map2_figure(coluna = column, estado = state),
			)
			graph1 = graph1_figure(camada = layer, coluna = column, estado = state)
			return map2, graph1
		if layer == 3:
			map2 = dcc.Graph(
				id        = 'map2',
				className = 'map2',
				figure    = map2_figure(coluna = column, estado = state),
			)
			graph1 = graph1_figure(camada = layer, coluna = column, estado = state, ibge = city)
			return map2, graph1
	elif 'state' in change_id:
		map2 = dcc.Graph(
			id        = 'map2',
			className = 'map2',
			figure    = map2_figure(coluna = column, estado = str(state)),
		)
		graph1 = graph1_figure(camada = 2, coluna = column, estado = str(state))
		return map2, graph1
	elif 'city' in change_id:
		map2 = dcc.Graph(
			id        = 'map2',
			className = 'map2',
			figure    = map2_figure(coluna = column, estado = str(state)),
		)
		graph1 = graph1_figure(camada = 3, coluna = column, estado = state, ibge = int(city))
		return map2, graph1