Why does Panel Column change Python dict to JSON(dict)? And how to use the converted object?

"""Panel Column seems to convert Python dict to JSON(dict). Is this intented 
behaviour or a bug?
from panel import Column

def feature_or_a_bug():
    keys = [f'class_{i}' for i in range(1, 11)]
    values = [f'tag_{i}' for i in range(1, 6)]
    dictionary = {key: values for key in keys}
    dictionary['classes'] = [f'class_{i}' for i in range(1, 11)]
    dictionary_in_a_column = Column(dictionary)

def main():

if __name__=='__main__':


{'class_1': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 'tag_5'], 'class_2': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 'tag_5'], 'class_3': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 'tag_5'], 'class_4': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 'tag_5'], 'class_5': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 'tag_5'], 'class_6': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 'tag_5'], 'class_7': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 'tag_5'], 'class_8': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 'tag_5'], 'class_9': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 'tag_5'], 'class_10': ['tag_1', 'tag_2', 'tag_3', 'tag_4', 
'tag_5'], 'classes': ['class_1', 'class_2', 'class_3', 'class_4', 'class_5', 'class_6', 'class_7', 'class_8', 'class_9', 'class_10']}
<class 'dict'>
<class 'panel.pane.markup.JSON'>

Can someone answer the questions? I can’t get any values out of the JSON(dict).

" A Column layout can either be instantiated as empty and populated after the fact or using a list of objects provided as positional arguments. If the objects are not already panel components they will each be converted to one using the pn.panel conversion method."

from Column — Panel v1.3.6

However, I can’t find the pn.panel conversion method. I’d be grateful if someone could point me to the relevant documentation. Presumably the method in case converts a Python dict into Panel JSON object.

pn.panel docstring found here.
(If you wish to find the location of the code where something is implemented within Python, just use obj.__module__.

As you noted, when you put an object into pn.Row or pn.Column, Panel converts it to a panel object in order to render it.
Thereby, in this particular case, the objects contained in the Column would be the converted dictionary into the JSON object that can be rendered.

If you wish to access the dictionary, you have to access it as an object of the pane created by pn.panel, which is JSON.


returns the initial dictionary object you were looking for: <class 'dict'>

1 Like