Hello everyone, happy day.
I need to please access the value of the URL with which the program was called, but it must be before going through the Callback. The idea is that the user’s name comes there and with this you can fire a SELECT to a database and build a menu, but until now I have not been able to assign that value without being able to go through the callback, and thus it is of no use to me since The menu is built before being able to assign the user that comes in the URL.
I haven’t been able to take it.
I really need your help.
I have performed all the tests available to a novice.
Thank you so much,
The program is as follows:
import dash
from dash import Dash, html, dcc, Input, Output,callback
import dash_bootstrap_components as dbc
import pandas as pd
import psycopg2
from pages import mmg_3
from pages import eng
import flask
app = Dash(name, use_pages=True)
def rec_enlaces(n_pos):
return enlaces[n_pos-1]
def generate_li(text_li):
a = html.Li(children=[generate_team_a(i, j) for i, j in opclink.items()],
value=text_li,
className="mr-2",
id=str(text_li))
return a
def generate_team_a(text_a, n_pos):
a = html.A(children=str(text_a),
href=rec_enlaces(n_pos),
className="mr-3",
id=str(text_a))
return a
PSQL_HOST=“127.0.0.1”; PSQL_PORT=“5432”; PSQL_USER=“__graph”; PSQL_PASS=mmg_3.valorumask(eng.__PALCLA); PSQL_DB=eng.__DBRMS
connection_address=“”“host=%s port=%s user=%s password=%s dbname=%s”“” % (PSQL_HOST, PSQL_PORT, PSQL_USER, PSQL_PASS, PSQL_DB)
connection = psycopg2.connect(connection_address)
#################################################################################################
I need to retrieve the URL (‘path’, ‘search’) to extract the user name and access the database with that user,
before the Callback and assign it to the USERNAME variable. !!!
#####################################################################################
b_cur = connection.cursor()
b_cur.execute("select comg.nombre_programa, comg.descripcion
from opc_menugraph comg, for_proggraph cfg
where comg.nombre_programa = cfg.nombre_programa \
#### HERE I NEED TO PLACE THE VARIABLE NOMBREUSUARIO THAT CONTAINS THE USERNAME THAT CONTAINS THE URL !!!!!
and nombreusuario = NOMBREUSUARIO \
and comg.cd_estatus = '001' \
and cfg.cd_estatus = '001' order by orden_ejecucion ")
menu = {‘menu’: [‘1’]}
opclink = {}
enlaces =
opciones =
usuario = ‘’
indi = 1
for field in b_cur:
opclink[field[1]] = indi
enlaces.append(field[0]
opciones.append(field[1])
indi += 1
app.layout = html.Div([
html.Table(
style={“margin-left”: “125px”},
children=[
html.Tr(
children=[
html.Td(
children=[
html.Ul(
className=“nav”,
children=[
html.Li(
children=[
html.A(
href=“#”,
children=[
“OPCIONES DISPONIBLES”,
html.Span(
className=“flecha”, children=[“◥”]
),
],
),
html.Hr(),
html.Ul(className=“nav”,
children=[generate_li(i) for i in menu])
, ]
)],
)]
),
html.Td(
children=[
html.Ul(
className=“nav”,
children=[
html.Li(
children=[
html.A(
href=“http://127.0.0.1:8050/”,
children=[“REGRESAR”],
),
html.Hr(),
])],)]
),]
)],
),
dcc.Location(id='path'),
html.Div(id='output'),
dash.page_container
])
@app.callback(
dash.dependencies.Output(‘output’, ‘children’),
[dash.dependencies.Input(‘path’, ‘search’)])
def update_output(value):
####### Here it is recovered correctly, but I require it first, in order to execute the select with the
####### correct user, I must recover it before the callback !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
print('Request', value, '-------', flask.request.args)
usuario = value
return value
if name == ‘main’:
#app.run(debug=False, host=‘0.0.0.0’)
app.run(debug=True)