Here is my code calling testi_insert
-function with no errors in Jupyter Lab. The first cell:
import panel as pn
from testi_insert import testi_insert
pn.extension()
# Upload Excel files to the database.
upload = pn.widgets.FileInput(accept='.xlsx', multiple=True)
test = pn.bind(testi_insert, upload)
upload
Running the cell allows choosing a file or multiple files into the fileInput
. The second cell:
test()
However, when I add a button from which I’d like to call the testi_insert
-function, I get
TypeError: testi_insert takes 1 positional argument but 2 were given
when clicking the button. Here is the code for calling testi_insert
from a button:
import panel as pn
from testi_insert import testi_insert
pn.extension()
# Upload Excel files to the database.
upload = pn.widgets.FileInput(accept='.xlsx', multiple=True)
test = pn.bind(testi_insert, upload)
upload_btn = pn.widgets.Button(name='Upload file(s)')
upload_col = pn.Column('# Upload file(s)', upload, upload_btn, align='center')
upload_btn.on_click(test)
upload_col
And here is the testi_insert
-function signature (it is printing the sql strings used in the actual insert function to see if they’re correct). I have tried adding an extra input to the signature but it doesn’t have any effect.
def testi_insert(files: list[IOBase]) -> None:
Could someone tell me what is wrong in my approach?
Another attempt to make this work was
# Upload Excel files to the database.
upload = pn.widgets.FileInput(accept='.xlsx', multiple=True)
test = pn.bind(testi_insert, upload)
button = pn.widgets.Button(name='Upload file(s)')
upload_btn = pn.bind(test, button.param.clicks)
upload_col = pn.Column('# Upload file(s)', upload, button, align='center')
upload_col
But with this the button click does not do anything. Changing the button
in upload_col
to upload_btn
results in AttributeError: 'function' object has no attribute 'owner'
.