Returning both text and plots from server to client

I am trying to use server functions to return both a pyplot graph and textual data to an anvil form. I have succeeded in returning the pyplot, but how do I at the same time return some text to the same form, and put it in a text area?

I’ve tried returning both the graph and the text through “return anvil.mpl_util.plot_image(), utskrift” (utskrift is Norwegian for print-out, a cummulated text string), but anvil will not accept this way of doing it.

So how can this challenge be overcome?

Hi. I simply used a table to hold the text info, and allowed the client side to get the info from the table. Simple, really! :slight_smile:

1 Like

If security becomes an issue – users reading rows that don’t belong to them – make the table inaccessible to the Client, and return just the specific table row to the Client.

No, client cannot read the table, only client app, the textArea is inactive, so there is a stop sign when You hover over it. But maybe there is another way, using another server function to read from the table and return it as a string?

I’ll rephrase what I said, to try to avoid confusion.

Your Server App (the part of your app that runs on the Server) can return the database table row, containing a text column and a media column, directly. (Maybe that’s what it is already doing.)

In that case, the Client App (the part of your app that runs in the browser) is receiving the row values directly. The Client App can receive that row, even if it has no access at all to the table as a whole. This helps avoid any security holes, that a nasty user could exploit.

If you don’t want to return the entire table row, you could just return the string and the Media Object as a tuple (ordered pair).

Hi. Thanks. I think that is filtered through the grid view. I agree that a server function should generate that view. I will not be exposing anything that is sensitive. The table returns data that has been accumulated by the users, and viewing the app is restricted to only those who have the URL. I’m doing this as part of an educational project, it is only supposed to be visible for and used by my teachers. Anyway thanks for the tips. I appreciate that.

And I use the method described last in your post to display data and image, the function returns the media object to the image and the text is generated through adding on to an accumulative string, adding data from the table by string += string + "Info …: "+str(datafield) + “\n” in some lines of the code, that string is returned to the client side and put in a read only textarea.