Make it easy to print to the app! #1391
Replies: 5 comments
-
Hi @codeananda, you can set
You can use any logging mechanism as you wish. See our docs for an example. |
Beta Was this translation helpful? Give feedback.
-
Hi @codeananda, you can also write logs to a file, and view the tail of a file with Ex: Also, like @mturoci mentioned, setting |
Beta Was this translation helpful? Give feedback.
-
@codeananda When you say "printed to the app" do you mean you would like the content of Based on the answer to this I have some suggestions, but I want to make sure we are understanding your request |
Beta Was this translation helpful? Give feedback.
-
@mtanco I meant printing to the app itself. One reason for this is that I'm using plotly and this makes using the terminal for debugging impossible (see #1374 I just opened). I've also been developing locally so wasn't worrying about other people seeing what I push to the app. I'm inspired by Streamlit with their magic and @mturoci thanks for the @azim-b Being honest, I've never used logging before (probably a DS/ML sin, I know!) so it feels much less natural/overkill to do this than printing (especially when checking if |
Beta Was this translation helpful? Give feedback.
-
It would need to be custom, since in general Wave is focused on building web apps, but here are some functions for "logging" to your screen: from h2o_wave import main, app, Q, ui
import pandas as pd
@app('/')
async def serve(q: Q):
create_log_content(q)
wave_log(q, "testin")
wave_log(q, "testin moar")
df = pd.DataFrame([1, 1, 2], columns=["test"])
wave_log(q, df)
print(df)
await q.page.save()
def create_log_content(q: Q):
# Each browser tab sees only their own logs
q.client.log_content = "# My Logs\n"
q.page["logs"] = ui.markdown_card(
box="10 1 -1 -1",
title="",
content=q.client.log_content
)
def wave_log(q: Q, content):
content = str(content)
content = content.replace("\n", "\n\n")
content += "\n\n*---------*\n\n"
q.client.log_content += content
q.page["logs"].content = q.client.log_content |
Beta Was this translation helpful? Give feedback.
-
Yesterday was my first day using wave and I spent 5 hours pulling my hair out and feeling very confused.
One thing I found particularly frustrating was that you cannot easily print info directly to the app. If you run
print()
from your .py file it prints to the terminal which gets clogged with loads of other output so it's hard to tell what is happening.For example, when loading a dataframe, it would be nice if I could run
df.head()
or evenprint('dataframe loaded successfully')
. All DSs/MLEs do this countless times per day in jupyter notebooks... but it is very unintuitive in wave. For example, in streamlit anything written on its own is automatically printed to the app. Plus, they have thewrite()
function/method. This is one of the first things they cover in their docs and makes debugging your apps an intuitive experience.What is the recommended way to do this with wave? Adding this to your docs would be super helpful.
Beta Was this translation helpful? Give feedback.
All reactions