DynamicMap cannot be displayed without explicit indexing

I have created a function that has one argument: the column name of a DataFrame. According to that value, it shows a graph that has the x-axis based on that column.

def make_graphs(filter):
...
return chart

Now I want to create a dynamic map to select the column from a list and change that graph. So I created another function for that:

def show_graph():
    filter_data = ["Gender", "Seniority"]

    dyn_map = hv.DynamicMap(make_graphs, kdims=["filter"])
    dyn_map.redim.values(filter=filter_data)
    dyn_map.redim.default(filter_data[0])
    dyn_map.opts(framewise=True)
    figure = hv.render(dyn_map)

    layout = bh.layouts.row(figure, sizing_mode="scale_width")
    bh.io.show(layout)

but when I run it, I get the error message:

DynamicMap cannot be displayed without explicit indexing as 'filter' dimension(s) are unbounded. 
Set dimensions bounds with the DynamicMap redim.range or redim.values methods.
Process finished with exit code 0

Any idea why?

I ran into the same issue. The way I get around it is to explicitly define the dimensions rather than depending on the text parsing of Holoviews.

So in your code I’d change it to:

def show_graph():
    filter_data = ["Gender", "Seniority"]

    filter = hv.Dimension('filter', values=filter_data, default=filter_data[0])
    dyn_map = hv.DynamicMap(make_graphs, kdims=[filter]) # note removal of quotes
    dyn_map.opts(framewise=True)
    figure = hv.render(dyn_map)

    layout = bh.layouts.row(figure, sizing_mode="scale_width")
    bh.io.show(layout)

Not sure if it is a bug or not. It seems like a bug, since the examples all use redim.

HI. I used your code and the result is the plot for default filter, that is, “Gender”, but there is no way to Select “Seniority”. No selection widget appear. Any idea why?

I’ve had trouble making Bokeh’s “show” method work with dynamic plots. Instead try:

import panel as pn
pn.serve(dyn_map)

I did this with the above code and it worked.

1 Like