I am a new user. Hard for me to grasp pn.bind all the way through, would appriciate help.
I would like to have one load_button
button which loads the file (if filename has changed) and returns a connection to a database.
The other function, when another run_button
when clicked will run, assuming data was loaded.
This is what I have so far but it does not work due to hashing issues of the input.
input_file = pn.widgets.TextInput()
load_button = pn.widgets.Button()
question = pn.widgets.TextInput() # question on the data
answer_button = pn.widgets.Button()
to bind these I do
con = pn.bind(get_db_connection, input_file=input_file, loading=load_button) # returns db connection
answer = pn.bind(run, running=answer_button, con=con, question=question) # get answer from calc
and the underlying methods are
@pn.cache
def run(running, con, question, nemo):
if not running:
yield "Calculation did not run yet"
return
if con is None:
yield "Data has not been loaded"
else:
yield [1,2,3]
@pn.cache
def get_db_connection(input_file, loading):
if loading:
con = csv_to_db(input_file)
yield con
else:
yield None
I get:
ValueError: User hash function <function _container_hash at 0x122b98430> failed for input {'running': False, 'con': <generator object get_db_connection at 0x1312ef920>, 'question': ''} with following error: ValueError("User hash function <function _container_hash at 0x122b98430> failed for input ('con', <generator object get_db_connection at 0x1312ef920>) with following error: ValueError("Could not hash object of type generator").").
Since con
cannot be hashed. However, I am not sure I even understand what’s going on. Does con hold the connection to the database or not?
Maybe I should have global con
variable?
Would appreciate any help