Launch Python apps locally from Excel

Consider this…You’ve just developed an awesome web app with Python and you want to share it with your colleagues. How should you go about it? What are your options?

Matt Doyle
Apr 8 · 3 min read
Photo by Filiberto Santillán on Unsplash

Ideally you’d deploy your app on a cloud service (AWS, Google Cloud, Heroku, etc.) and simply direct potential users to a url. No fuss, no muss. But not always will you want your precious projects in the public domain. Or perhaps you don’t want to pay for the hosting service. Whatever the reason, you can still share your app for local use, for free.

Said no one…ever…I completely made that saying up, but it kind of holds true. As a developer you’re constantly building tools, potentially in different languages and using different programs. Your toys are scattered all over the shop. Where possible, try and keep things centralised to make life easy, not just for you, but also for your potential end users.

Consider your target audience’s level of experience. Are they all capable of interacting with the command line, activating virtual environments and opening their browser to the localhost with correct port number? And do they really want to have one more application open? Unlikely.

What about Excel? Can everyone open Excel and click one of these bad boys? Now we’re talking…

Bad boy. Image by author.

MS Excel is an absolute institution. I’d be surprised if there wasn’t a spreadsheet open on your PC as you read these very words! Admittedly, Excel is a bit long in the tooth when compared to the new and exciting programming languages available at the moment, but it is certainly the most prolific analytical tool out there.

This is where you can utilise the comfort and familiarity of a good-old excel macro button like a nice warm hug to the user. And all it takes is one line of VBA code behind the scenes.

Sub LaunchDashboard()command = Shell("C:\Users\" & LCase(Environ$("Username")) & "\Documents\Dasboard.bat", vbNormalFocus)End Sub

The above VBA code retrieves the Windows username to dynamically find the correct path to the batch file and runs it in the command prompt. “vbNormalFocus” leaves the command prompt open (as opposed to hidden) for visual feedback.

Now lets take a look at the actual batch (.bat) file used to open the command prompt, activate a virtual environment and then launch your dashboard in Chrome.

start http://127.0.0.1:8050/
call C:\Users\%USERNAME%\anaconda3\Scripts\activate
call conda activate dashboards
python "C:\Users\%USERNAME%\Documents\dashboard.py"
cmd /k
  • start http://127.0.0.1:8050launches default web browser at the localhost address and correct port (8050 in this case) to view the app.
  • call C:\Users\%USERNAME%\anaconda3\Scripts\activate — effectively turns the command prompt into an Anaconda prompt to be able to recognise “conda” commands. Note the use of %USERNAME% to dynamically get the Windows username.
  • call conda activate dashboards — activates the virtual environment.
  • python “C:\Users\%USERNAME%\Documents\dashboard.py” — runs the app with the dynamic file path.
  • cmd /k— keeps the command prompt window open for visual feedback.

Below is an example of the batch file being executed by the VBA code and successfully launching a dashboard on the localhost.

Successful execution of batch file and dashboard launch. Image the author.

The caveat to this example is that everyone you share your project with will need to maintain it in the same relative directory — so keep that file path simple. Users will also need to set up a virtual environment the same as yours. For the sake of brevity, I won’t go into that here, there are plenty of articles out there to guide you through that if needed, but trust me — it’s a cinch. In my opinion these minor details are more than compensated for by the practicality of “keeping your tools in one toolbox” and accessibility for everyone.

Give it a go and let me know your thoughts!

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data…

Sign up for Analytics Vidhya News Bytes

By Analytics Vidhya

Latest news from Analytics Vidhya on our Hackathons and some of our best articles! Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Matt Doyle

Written by

Curious programmer. Experienced in financial markets. Fan of a good dashboard!

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Matt Doyle

Written by

Curious programmer. Experienced in financial markets. Fan of a good dashboard!

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store