Make the database file to connect user selectable (maybe upload.dcc?)

Hi,

I have a question about a Dash app i made.

In this app at the start I have the database name hardcoded, now I would like to make this user selectable.

I have seen the Dash Upload Component (dcc.Upload) but this loaded when the app starts.

Is it possible to select a database file from the dcc.Upload and change the variable “Database” and the reload the app? Or is there a other solution. Its only to get the database name and path in the variable. i Know a varaible is not the best option is dash and is unsafe but its a fully local app. But if there is a better way please…

Hope the question is understandable, if not please say so.

Kind Regards!

Here the start code:

database = "1234_1234.db"

def create_connection(db_file) :
    try :
        conn = sqlite3.connect (db_file)
        return conn
    except Error as e :
        print (e)

    return None

conn = create_connection (database)


df = pd.read_sql ('SELECT time, Output FROM database', con=conn)

after this there are a couple of pandas data frames loaded with info from the database

and the the application is started

app = dash.Dash (__name__,
                 external_stylesheets=external_stylesheets)

app.config['suppress_callback_exceptions'] = True

app.layout = html.Div ([