datalayer / jupyter-ui

⚛️ React.js components 💯% compatible with 🪐 Jupyter https://jupyter-ui-storybook.datalayer.tech
https://jupyter-ui.datalayer.tech
Other
342 stars 47 forks source link

select kernel #99

Open zhenxxxx opened 1 year ago

zhenxxxx commented 1 year ago

Problem

I just want to know if there is a way to select the kernel in the jupyter server? For example, there is a menu that contains all kernel get from jupyter server. And I can select the different kernels in this menu.

And there is a way to set a remote jupyter server in UI?

echarles commented 1 year ago

You can configure the kernel name and server via props on the Jupyter context as listed on https://jupyter-ui.datalayer.tech/docs/components/context/

Doe it help? If you want to assign/change kernels, you can have a look at this example https://github.com/datalayer/jupyter-ui/blob/main/packages/react/src/examples/NotebookKernelChange.tsx

zhenxxxx commented 1 year ago

Thanks for your reply, how do I get all the kernels from the jupyter server, e.g. which api should I use?? I've seen examples, how does it determine which kernel to use, is it by specifying a kernel name?

echarles commented 1 year ago

You can list the available kernelspecs with

$  jupyter kernelspec list
Available kernels:
  python3               .../jupyter/kernels/python3
  python3-slow-start    .../jupyter/kernels/python3-slow-start

python3 or python3-slow-start will be the names you would use for the defaultKernelName.

zhenxxxx commented 1 year ago

Thanks, I will try it.

zhenxxxx commented 1 year ago

I use the defaultKernelName to select the kernel, but this doesn't seem to work, it's always use default kernel.

if (kernelManager) { 
      const kernel = new Kernel({
        kernelManager,
        kernelName: "python38_test",
        kernelType: "notebook",
        kernelSpecName: "python",
        serverSettings,
      });
      kernel.ready.then(() => {
        dispatch(notebookActions.changeKernel({ uid: NOTEBOOK_UID, kernel }));
        alert('The kernel is changed.')
      });
}

image

echarles commented 1 year ago

@alwayslovez Right, there was an issue which I have fixed in the 0.7.7 release. You will have to set the kernelSpecName to the name the command jupyter kernelspec list returns. So this would be:

if (kernelManager) { 
      const kernel = new Kernel({
        kernelManager,
        kernelName: "python38_test",
        kernelType: "notebook",
        kernelSpecName: "python",
        serverSettings,
      });
      kernel.ready.then(() => {
        dispatch(notebookActions.changeKernel({ uid: NOTEBOOK_UID, kernel }));
        alert('The kernel is changed.')
      });
}

PS: Your screenshot is showing pyrhon38_test - is that a typo ? it should be python38_test (with a t, not a r)

echarles commented 10 months ago

For example, there is a menu that contains all kernel get from jupyter server. And I can select the different kernels in this menu.

Working on that ATM with https://github.com/datalayer/jupyter-ui/issues/123

https://twitter.com/DatalayerIO/status/1743578268345753754