Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dash & XLwings. Attempting to pre-load Excel before Dash callback to save load time. #54

Open
karnrage opened this issue Jul 6, 2023 · 0 comments

Comments

@karnrage
Copy link

karnrage commented Jul 6, 2023

Windows 10 Enterprise for local. Windows Server 2022 Standard for the server

3.10 Python, Microsoft 365 Apps for enterprise, 0.28.7 xlwings

I have a web interface project that is using a connection between XLwings and Dash. The Excel file is large and takes about 15 seconds to load, while the calc only takes 5 seconds. Since it is setup to run over the web, each client will have their own instance of Excel. XLwings has a way to handle this.
Currently the setup is that once the user enters their setup and clicks submit, only then does the connection start.
If this was normal python, I could just start the connection earlier. However, with Dash the only connection between the layout, and the function definition is the Dash callback.
The goal is to load the Excel file as soon as the page is loaded, while that is happening the user would enter their parameters, the time that takes to load would be saved and the result return time would be shortened by that time.
*
I would like to use a chained callback. The first callback would load on page load with the xlWings connection. 'prevent_initial_call' would be false.
The final callback I have setup the 'prevent_initial_call' to True because I don't want this to run until they hit submit.
*
If I setup the connection as a variable or function, it doesn't look like you can pass these through the callback in anyway.
Project requirements are that the Excel and its VBA not be converted to Python/Dash.
Possible to launch one, or a few, Excels' on launch, and have XLwings grab the PID somehow? Would another Excel extension handle this? I know we're not supposed to use 'Global' variables, but that might fit this particular need.

Above this code part is the layout setup for Dash

@callback(
     #many Output and Inputs. Removed most for clarity.
     Output(component_id='table', component_property='data'),
     Input(component_id='yearSlider', component_property='value'),
)
def finalFxn(
#many parameters. Removed most for clarity.
parameter1,
parameter2
):
   with xw.App(visible=True) as app:
        wb = app.books.open(r"C:\Users\mike\Downloads\modified3-31.xlsm")
#logic
# excel cells = parameters from web
#logic
# parameters to web = excel 
return results, graph, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant