How can I use the same port for showing multiple plots?

I need to use hvplot from from IPython on a server, so the best strategy for me to view plots is to display them at some port using the function. While this works well, at the moment I need to pick a new port every time I show a different plot since apparently the ports stay in for the plot they’re created until the jupyter session ends.

For example this works fine (from the docs):

plot = air2d.hvplot(), port=8880)

But then if I try to plot it (or another plot) again in the same port (using the command, port=8880) again) I get the following error:

OSError                                   Traceback (most recent call last)
/tmp/ipykernel_8791/ in <module>
      1 hvplot.extension('plotly')
      2 plot = air2d.hvplot(width=800)
----> 3, port=8880)

~/miniconda3/envs/hvplot-env/lib/python3.7/site-packages/hvplot/ in show(obj, title, port, **kwargs)
     27         raise ValueError('%s type object not recognized and cannot be shown.' %
     28                          type(obj).__name__)
---> 29     _pn.pane.HoloViews(obj).show(title, port, **kwargs)

~/miniconda3/envs/hvplot-env/lib/python3.7/site-packages/panel/ in show(self, title, port, address, websocket_origin, threaded, verbose, open, location, **kwargs)
    423             self, port=port, address=address, websocket_origin=websocket_origin,
    424             show=open, start=True, title=title, verbose=verbose,
--> 425             location=location, threaded=threaded, **kwargs
    426         )

~/miniconda3/envs/hvplot-env/lib/python3.7/site-packages/panel/io/ in serve(panels, port, address, websocket_origin, loop, show, start, title, verbose, location, threaded, admin, **kwargs)
    682         server.start()
    683     else:
--> 684         return get_server(panels, **kwargs)
    685     return server

~/miniconda3/envs/hvplot-env/lib/python3.7/site-packages/panel/io/ in get_server(panel, port, address, websocket_origin, loop, show, start, title, verbose, location, admin, static_dirs, oauth_provider, oauth_key, oauth_secret, oauth_extra_params, cookie_secret, oauth_encryption_key, session_history, **kwargs)
    908     opts['cookie_secret'] = config.cookie_secret
--> 910     server = Server(apps, port=port, **opts)
    911     if verbose:
    912         address = server.address or 'localhost'

~/miniconda3/envs/hvplot-env/lib/python3.7/site-packages/panel/io/ in __init__(self, *args, **kwargs)
    252     def __init__(self, *args, **kwargs):
--> 253         super().__init__(*args, **kwargs)
    254         if state._admin_context:
    255             state._admin_context._loop = self._loop

~/miniconda3/envs/hvplot-env/lib/python3.7/site-packages/bokeh/server/ in __init__(self, applications, io_loop, http_server_kwargs, **kwargs)
    424             http_server_kwargs['ssl_options'] = context
--> 426         sockets, self._port = bind_sockets(opts.address, opts.port)
    427         self._address = opts.address

~/miniconda3/envs/hvplot-env/lib/python3.7/site-packages/bokeh/server/ in bind_sockets(address, port)
     72     '''
---> 73     ss = netutil.bind_sockets(port=port or 0, address=address)
     74     assert len(ss)
     75     ports = {s.getsockname()[1] for s in ss}

~/miniconda3/envs/hvplot-env/lib/python3.7/site-packages/tornado/ in bind_sockets(port, address, family, backlog, flags, reuse_port)
    160         sock.setblocking(False)
    161         try:
--> 162             sock.bind(sockaddr)
    163         except OSError as e:
    164             if (

OSError: [Errno 98] Address already in use

Is there any way around this? Some command to free up the given ports?


Hi @tomchor,

I’ve seen something written along the lines of:

import hvplot
import panel as pn

p = air2d.hvplot()
test = pn.panel(p).show(port=8088)

then try calling:


I’ve not tried the code myself but maybe of some help, thanks Carl.

Thanks! This definitely works :slight_smile: