Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using thebe with a local server #27

Open
psychemedia opened this issue Jun 18, 2021 · 3 comments
Open

Using thebe with a local server #27

psychemedia opened this issue Jun 18, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@psychemedia
Copy link

psychemedia commented Jun 18, 2021

Currently, thebe is hardwired to connect to a kernel launched from a BinderHub server using the following templated config as per

# Update the doctree with some nodes for the thebe configuration
:

    # Update the doctree with some nodes for the thebe configuration
    thebe_html_config = f"""
    <script type="text/x-thebe-config">
    {{
        requestKernel: true,
        binderOptions: {{
            repo: "{org}/{repo}",
            ref: "{branch}",
        }},
        codeMirrorConfig: {{
            theme: "{codemirror_theme}",
            mode: "{cm_language}"
        }},
        kernelOptions: {{
            kernelName: "{kernel_name}",
            path: "{path_to_docs}{str(Path(docname).parent)}"
        }},
        predefinedOutput: true
    }}
    </script>
    """

It would be useful to be able to specify a local connection to an already running server rather than a BinderHub connection, eg as per jupyter-book/jupyter-book#199 and jupyter-book/jupyter-book#1206.

This would require a template of the form (untested - {} may be messed up...):

thebe_html_config = f"""
    <script type="text/x-thebe-config">
    {{
        bootstrap: true,
        kernelOptions: {{
          name: "{kernel_name}",
          serverSettings: {{
            "baseUrl": "{thebe_server_url}",
            "token": "{thebe_server_token}"
          }}
      }}
    }}
    </script>
    """

to give a config such as the following for a local server run as jupyter notebook --NotebookApp.token=test-secret --NotebookApp.allow_origin='http://localhost:8888'

<script type="text/x-thebe-config">
{
  bootstrap: true,
  kernelOptions: {
    name: "python3",
    serverSettings: {
      "baseUrl": "http://127.0.0.1:8888",
      "token": "test-secret"
    }
  },
}
</script>

As for settings in Jupyter book, maybe add something like the following to jupyter_book/config_schema.json:

"launch_buttons": {
            "type": "object",
            "properties": {

                # ...

                "thebe_server_url": {
                    "type": "string"
                },
                "thebe_server_token": {
                    "type": "string"
                }
            }

with default set via jupyter_book/default_config.yml as per something like:


# Launch button settings
launch_buttons:
 # ...
  thebe_server_url           : "" # Use a specified server URL (must be started with appropriate --NotebookApp.allow_origin setting)
  thebe_server_token      : "" # thebe_local_url server must be started with a corresponding --NotebookApp.token value.
  

In a default setup, as per above, these would then be set as per:

  thebe_server_url           : "http://127.0.0.1:8888"
  thebe_server_token      : "test-secret"

Some logic would then be required to determine which thebe template to use based on relative settings of binderhub_url and thebe_local_url .

The Launching from MyBinder message in sphinx_thebe/_static/sphinx-thebe.js would also need updating as appropriate.

It would possibly be neater to have a Jupyter Book setting thebe: binderhub | server | none rather than true false and then thebe_server_url would work equally for BinderHub. But that could break backwards compatible config files.

I've started trying to explore this route by mnaully editing Jupyter Book HTML pages in the context of a jupyter-server-proxied Jupyter Book. Notes here: https://github.com/ouseful-testing/jupyter-book-server-proxy

@psychemedia psychemedia added the enhancement New feature or request label Jun 18, 2021
@akhmerov
Copy link
Contributor

akhmerov commented Jun 20, 2021

Would #25 address this need?

@psychemedia
Copy link
Author

@akhmerov Ah, so is that suggesting just dumping thebe_config into <script type="text/x-thebe-config">?

So to backtrack from that, some way would need to setup the thebe_config structure correctly.

I also note for even more generality, it would be worth considering a case where ThebeLab might also support Jupyterlite (eg jupyter-book/thebe#412 .

@bethac07
Copy link

+1 to this being useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants