cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Python optimizer / PowerApps / Automate

Hi all,

 

My use case is as follows: given user input (a single monetary value), I would like to optimize a set of given items.

 

My initial thoughts are:

1. Build a PowerApps app + connect in powerbi, that just takes user input

2. Connect to Flow -- when user input received, execute Flow (power automate)

3. This Flow will in turn run a python file that calls an optimizer library (PuLP) -- based on the input variable, and constraints, selects items that maximize that input. This may be possible using Azure Function API? 

4. Then the result of that py file is sent back to Flow, and then back to powerapps somehow...

 

I am fairly new to powerapps / powerbi, so I'd like to get your suggestions. Is this a feasible approach highlighted above?

2 ACCEPTED SOLUTIONS
Community Support
Community Support

HI @thehamzam,

#1, You can create PowerApps with parameters, then they allow you to input parameters.

Launch and Param functions in Power Apps 

#2, Please check the following link about use PowerApps with ms flow.

Start a flow in a canvas app 

#3, You can do these with Azure functions, you can take a look at the below link to know more about these.

Create your first function in the Azure portal 

#4, You can refer to the following blog about invoke the Azure function in flow:

Invoke an Azure Function Using Power Automate (Flow)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Hi @thehamzam,

Sorry for the late response. Did you mean to use python to connect/manage Azure VM? If that is the case, you can refer to the following documents:
Create and manage Windows VMs in Azure using Python 

Reference link about azure function network operations:

Azure Functions networking options 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

17 REPLIES 17
Community Support
Community Support

HI @thehamzam,

#1, You can create PowerApps with parameters, then they allow you to input parameters.

Launch and Param functions in Power Apps 

#2, Please check the following link about use PowerApps with ms flow.

Start a flow in a canvas app 

#3, You can do these with Azure functions, you can take a look at the below link to know more about these.

Create your first function in the Azure portal 

#4, You can refer to the following blog about invoke the Azure function in flow:

Invoke an Azure Function Using Power Automate (Flow)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Hi @v-shex-msft ! Thanks for the great help!

 

Sorry about delay -- I am trying to do step3 and having this issue

"One or more errors occurred. (Error while copying content to a stream.)"

 

I followed step by step -- i am logged into az, I am using their HTTP Example, but still nothing worked. If you know of a fix for this, I'd appreciate it -- I will keep you updated. thanks again.

It fails at this command: func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"

HI @thehamzam,

So you mean you can't finish the create function app steps to redirect to the detail develop menu?
If this is a case, have you checked you have corresponded permissions to do operate with azure functions apps?
In addition, you can contact azure admin/support with detailed error messages and these request id to get further support.
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft !

 

Amazing, that was the issue -- thanks for your help again.

If you dont mind, I am running into an issue again. The function is now locally working, but when I try to deploy onto Azure, I get the following error traceback:

Exception while executing function: Functions.HttpExample Result: Failure
Exception: PulpSolverError: Pulp: Error while executing /home/site/wwwroot/.python_packages/lib/site-packages/pulp/apis/../solverdir/cbc/linux/64/cbc
Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 355, in _handle__invocation_request
call_result = await self._loop.run_in_executor(
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 542, in __run_sync_func
return func(**params)
File "/home/site/wwwroot/HttpExample/__init__.py", line 22, in main
return func.HttpResponse(f"{optimize(name)}")
File "/home/site/wwwroot/HttpExample/__init__.py", line 100, in optimize
model.solve(solver)
File "/home/site/wwwroot/.python_packages/lib/site-packages/pulp/pulp.py", line 1737, in solve
status = solver.actualSolve(self, **kwargs)
File "/home/site/wwwroot/.python_packages/lib/site-packages/pulp/apis/coin_api.py", line 101, in actualSolve
return self.solve_CBC(lp, **kwargs)
File "/home/site/wwwroot/.python_packages/lib/site-packages/pulp/apis/coin_api.py", line 159, in solve_CBC
raise PulpSolverError("Pulp: Error while executing "+self.path)


 

Based on this file: https://github.com/coin-or/pulp/blob/master/pulp/apis/coin_api.py

It looks like it fails here on line 158/9:

        if not os.path.exists(tmpSol):
            raise PulpSolverError("Pulp: Error while executing "+self.path)

maybe when deploying, it doesnt have / cant find the os path?

 

Couldn't find the same issue on the web, except this: https://github.com/Azure/azure-functions-python-worker/issues/465 which suggests using Docker -- 

but is there an alternative to Docker? how should  I proceed?

 

thanks for your help

ah, please ignore -- i fiex with parameter keepFiles=True

I now have this issue lol

 

Exception while executing function: Functions.HttpExample Result: Failure
Exception: OSError: [Errno 30] Read-only file system: 'Budget_model-pulp.mps'
Stack:   File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 355, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 542, in __run_sync_func
    return func(**params)
  File "/home/site/wwwroot/HttpExample/__init__.py", line 22, in main
    return func.HttpResponse(f"{optimize(name)}")
  File "/home/site/wwwroot/HttpExample/__init__.py", line 100, in optimize
    model.solve(solver)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/pulp/pulp.py", line 1737, in solve
    status = solver.actualSolve(self, **kwargs)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/pulp/apis/coin_api.py", line 101, in actualSolve
    return self.solve_CBC(lp, **kwargs)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/pulp/apis/coin_api.py", line 114, in solve_CBC
    vs, variablesNames, constraintsNames, objectiveName = lp.writeMPS(tmpMps, rename = 1)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/pulp/pulp.py", line 1611, in writeMPS
    return mpslp.writeMPS(self, filename, mpsSense = mpsSense, rename = rename, mip = mip)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/pulp/mps_lp.py", line 223, in writeMPS
    with open(filename, "w") as f:
 

i understand i cant write to the azure fn directory -- but im wondering how its possible to work around this if its in a library im calling -- maybe create a blob storage for this "filename" -- will have to keep digging into it

i'm trying to play around wtih some parameters when calling the function that is in the pulp library, no luck yet - will keep you posted

HI @thehamzam,

>>i understand i can't write to the azure fn directory -- but im wondering how its possible to work around this if its in a library im calling -- maybe create a blob storage for this "filename" -- will have to keep digging into it

Yes, detect the physical file/directory path operations on business cloud servers should be a pain to process.
AFAIK, these types of operations almost blocked by permissions, policy, and security reasons except you are working on personal servers.

One workaround is to use a temporary server/service which you have enough permissions to manage and configurations to do these sensitive operations. (azure side do simple read/write operations)

Steps:

Azuree Server:
1. Common operate
2. Common operate
3. Common operate
Azure server to temporary server:
1. Sensitive operations
2. Loading result data to Azure Server
Azuree Server:
4. Common operate
5. Common operate
6. Common operate

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

hi @v-shex-msft ,

 

great, do you think I'll be able to use a non-azure Windows VM? if so, I'd appreciate documentation / examples -- seems like we might need VNet integration?

 

 

HI @thehamzam,

In fact, this temporary server/service not has limits on device types.
You can even deploy these on your personal laptop/PC if you can confirm it worked online and has permission to receiver these remote operations and requests.😊

Notice:

Above is a sample, you can use it to do tests but please not really deploy it to your personal laptops. It is are hard to confirm their status(device hardware, network, and power status) and keep working online every time.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

amazing @v-shex-msft ! do you know where I can find examples of connecting to VM?

Hi @thehamzam,

Sorry for the late response. Did you mean to use python to connect/manage Azure VM? If that is the case, you can refer to the following documents:
Create and manage Windows VMs in Azure using Python 

Reference link about azure function network operations:

Azure Functions networking options 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

ah @v-shex-msft  i actually meant a non-azure personal vm 

Hi @thehamzam,

Normally you can do these with two methods, connect with RDP(Remote Desktop Protocol) or deploy web service on your device. 

For your scenario, I think web service should suitable for your requirement.

Configuring a Web Server for Web Deploy Publishing (Web Deploy Handler) 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

hi @v-shex-msft , just following up to see if you have had a chance to check 🙂

Frequent Visitor

is there a way to avoid powerapps ? 

Hi @thehamzam,

So you mean you want to directly use ms flow to invoke python script and azure functions without power app?
If this is the case, you can directly use ms flow to do these things without the power app. The first two steps not necessary in these operations, you can avoid them and only use ms flow.
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Microsoft Ignite

Microsoft Ignite with Arun Ulag

Featured Session: Drive Data Culture with Power BI- Vision, Strategy & Roadmap. Register here https://myignite.microsoft.com #MSIgnite #PowerPlatform #Power BI ​

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors
Users online (200)