PyXLL and Anvil

I have used PyXLL for several years. I tried the Anvil app yesterday and today.

First, I built an ‘Anvil only’ app – fairly straightforward, easy, seems to work as advertised – in conclusion, no issues.

Second, I built an ‘Anvil + PyXLL’ app – little bit tricky for me. Even after getting it to work, I have issues.

Here is my test server module (ServerModule1):

import anvil.server

from anvil_pyxll.server import xl_func

# This is a server module. It runs on the Anvil server,
# rather than in the user's browser.
#
# To allow anvil.server.call() to call functions here, we mark
# them with @anvil.server.callable.
# Here is an example - you can replace it with your own:
#

@xl_func
def ABCsay_hello(name_parameter):
  return 42

@xl_func
@anvil.server.callable
def hypotx(a,b):
  return (a**2 + b**2)**0.5

@xl_func
@anvil.server.callable
def subx_a_and_b(a,b):
  return a-b

The code above works, PyXLL uses this code successfully. Actually, the ABCsay_hello function is recognized but returns an (#N/A) error in Excel.

Now, when the functions are edited, PyXLL/Excel does not recognize the changes. I’ve attempted several ways of forcing PyXLL/Excel to use the edited code.

   run the edited app
   republish the edited app
   close the edited app
   change the uplink token
   deep reload of PyXLL/Excel
   close Excel
   restart the computer

Seems to me, something is broken in the PyXLL client to PyXLL server connection. Maybe I have something wrong in my setup.

Here is the link to the app online: BigTest (Anvil chose the name).

In the text area of the online app:

   for e in anvil.server.call('pyxll.get_xl_funcs'):
     txt = txt + str(e['func_name']) + ' \n'
   txt = txt[:-1]
   self.pyx_funcs_area.text = txt

the PyXLL functions are gathered and presented. This seems to prove that the PyXLL server is working correctly. My guess is that something is not working in the PyXLL client.

Hi!

the PyXLL client code uses the Anvil Uplink feature to call your code on the Anvil servers (https://anvil.works/docs/uplink). Once you have made changes to your server code, calls from PyXLL will call the latest published server code without needing to reload PyXLL (unless your function names or arguments have changed, in which case reloading the PyXLL add-in is all that should be required).

Since you are not seeing the latest version of your functions when calling from Excel, one possibility could be that you are not using the right Anvil token in your pyxll.cfg file. The token is specific to an Anvil app, and so if you started with one app and then created another (or cloned one to make changes) then you would need to update the uplink token in your PyXLL config.

If you need more help please share your app (https://anvil.works/docs/editor/cloning) and your PyXLL log file (with debug logging enabled).

I hope this helps!
Tony

1 Like

Tony fixed the repo in Github and now I see no problems.

I emphasize the first paragraph in Tony’s comments above.