Skip to content

Commit ee80370

Browse files
authored
Maintain dict type in components() (bokeh#8416)
* Maintain dict type in components() * Single return point in components()
1 parent 6b2a3c4 commit ee80370

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

bokeh/embed/standalone.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ def components(models, wrap_script=True, wrap_plot_info=True, theme=FromCurdoc):
209209

210210
# now convert dict to list, saving keys in the same order
211211
model_keys = None
212+
dict_type = None
212213
if isinstance(models, dict):
213214
model_keys = models.keys()
215+
dict_type = models.__class__
214216
values = []
215217
# don't just use .values() to ensure we are in the same order as key list
216218
for k in model_keys:
@@ -238,14 +240,13 @@ def div_for_root(root):
238240
# 3) convert back to the input shape
239241

240242
if was_single_object:
241-
return script, results[0]
243+
result = results[0]
242244
elif model_keys is not None:
243-
result = {}
244-
for (key, value) in zip(model_keys, results):
245-
result[key] = value
246-
return script, result
245+
result = dict_type(zip(model_keys, results))
247246
else:
248-
return script, tuple(results)
247+
result = tuple(results)
248+
249+
return script, result
249250

250251
def file_html(models,
251252
resources,

bokeh/embed/tests/test_standalone.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# Standard library imports
2121
from mock import patch
22+
from collections import OrderedDict
2223

2324
# External imports
2425
import bs4
@@ -95,6 +96,10 @@ def test_return_type(self):
9596
assert isinstance(divs, dict)
9697
assert all(isinstance(x, string_types) for x in divs.keys())
9798

99+
_, divs = bes.components(OrderedDict([("Plot 1", plot1), ("Plot 2", plot2)]))
100+
assert isinstance(divs, OrderedDict)
101+
assert all(isinstance(x, string_types) for x in divs.keys())
102+
98103
@patch('bokeh.embed.util.make_globally_unique_id', new_callable=lambda: stable_id)
99104
def test_plot_dict_returned_when_wrap_plot_info_is_false(self, mock_make_id):
100105
doc = Document()

0 commit comments

Comments
 (0)