4 ms·
There's an api to update a Colab cell publicly available? That's wild. I thought for sure it would be locked down.
by Something1234 3y ago
There's an api to update a Colab cell publicly available? That's wild. I thought for sure it would be locked down.
- bsimpson 3y agoBest solution I've found is to paste the whole thing into a cell with this header #@title Give your cell a headline %%js_module where js_module is defined here: # Copyright 2023 Google LLC. # SPDX-License-Identifier: Apache-2.0 from IPython.core.display import display, HTML from IPython.core.magic import register_cell_magic import time @register_cell_magic def js_module(line, cell): if cell.startswith('http'): src, hash = cell.split('#') if '#' in cell else [cell, ''] timestamp = time.time() if 'cachebust' in line else '' display(HTML( "<script type = 'module' src = '{src}?{timestamp}'></script>".format(src = src, hash = hash, timestamp = timestamp) )) else: display(HTML( "<script type = 'module'>{cell}</script>".format(cell = cell) )) The #@title lets you collapse the cell, so the JavaScript isn't showing. Colab has a strong philosophy of ensuring the user can see everything they're running, so I don't think there's a better way to encapsulate the bundled JS.