Label is not displaying result but instead showing up in colab notebook

Hello, I just wanted to first say this is my first time using Anvil. I am having trouble trying to display a result of a function in my colab notebook on a label in anvil. The uplink was enabled successfully, but everytime I run the web app, the result goes to my notebook. This is the code in Anvil:

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 
def enter_click(self, **event_args):
    """This method is called when the button is clicked"""
    music_rec = anvil.server.call('musicrec2', self.emotion_input.text)
    self.label_2.text = music_rec

And this is what I have in Colab:


And the web app looks like this:

Whenever I press enter, nothing will show up on Anvil, and instead, the result will show up in Colab like this:

The output that’s showing up in Colab is what I’m trying to display on the web app on label_2.

You are just printing the results. You should be returning them instead.

Replace all print(song_rec...) statements with return song_rec...

3 Likes

Hello, thank you for the suggestion. I tried it, but got this error instead:

Welcome to the Forum!

To see what kinds of data you can pass through a server call, see Valid arguments and return values.

You’ll need to convert the data to one of these formats before your can return it through Anvil.

2 Likes

Hello, thank you for the reply! Using both suggestions, I was able to figure out the issue. I used the .to_markdown() for the datasets with return statements, and that seemed to fix the problem. Thanks again to you both!

You can leverage that Markdown-format text! See RichText.

2 Likes