I am returning a list which contains a set of panel widgets.
one of the elements are :
[0] Markdown(str, sizing_mode=‘stretch_width’)
How do I access the text or anything written inside this Markdown widget?
Hi @simran
Could you provide a minimum, reproducible example? Then its much easier to explain. Thanks.
Sure @Marc
row_list = []
for row in cur.execute("SELECT * FROM approval_deploy"):
new_row = pn.Row(row[0], row[1],pn.layout.Spacer(width=1), row[2],pn.layout.Spacer(width=1), row[3], row[4],row[5])
row_list.insert(0, new_row)
row_values.extend(row_list)
I am fetching data from database and returning row_values.
When I print row_values:
Row(sizing_mode=‘stretch_width’)
[0] Markdown(str, sizing_mode=‘stretch_width’)
[1] Markdown(str, sizing_mode=‘stretch_width’)
[2] Spacer(sizing_mode=‘stretch_width’, width=1)
[3] Markdown(str, sizing_mode=‘stretch_width’)
[4] Spacer(sizing_mode=‘stretch_width’, width=1)
[5] Markdown(str, sizing_mode=‘stretch_width’)
[6] Markdown(str, sizing_mode=‘stretch_width’)
[7] Markdown(str, sizing_mode=‘stretch_width’)
Question 1: Why does string changes to Markdown widget when I am inserting in pn.Row?
Question 2: How do I access the text written inside the Markdown widget?
Hi @sam_panel
This example is minimal but not reproducible. I.e. I cannot run it end to end for multiple reasons
Try refactoring the example a bit so that imports Panel and uses a list of rows instead of getting the from the database etc. All such that the example can be run end to end by anyone. Thanks
When you call something like pn.Row(obj1, obj2, ...)
, each object if it is not a Panel object already is going to be casted by Panel automatically to its representation using pn.panel
under the hood I think. When you pass a string to pn.panel
it is to display with a Markdown pane. If that’s not what you want, you should create the pane that you want manually with e.g. pn.pane.HTML('some html')
.
The Markdown
component is not a widget but a pane, see the component gallery for reference. Panes have an object
attribute from which you can access the object they display, here it’s going to be a string and for instance the DataFrame pane would hold a Pandas DataFrame object.
Sure, I will keep this in mind.