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

Make it easier to develop local changes to js #33

Open
erikfrey opened this issue Aug 19, 2021 · 5 comments
Open

Make it easier to develop local changes to js #33

erikfrey opened this issue Aug 19, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@erikfrey
Copy link
Collaborator

html.io currently refers to a static cdn for the js, which is awkward for trying out changes to the js itself.

We have a hacky example of local dev of js here: https://colab.sandbox.google.com/gist/erikfrey/eb8b138dce06f7c2135e9d9690a09a8e/local_dev.ipynb#scrollTo=NaJDZqhCLovU

A proper solution might be to introduce an arg to html.render that takes in a different static path, and that starts up a temp webserver.

@o-Oscar
Copy link
Contributor

o-Oscar commented Aug 23, 2021

For anyone stumbling on this thread, for me the most convenient way to make local dev to js files is to run the following script on brax's root folder :

import http.server

class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_my_headers()
        http.server.SimpleHTTPRequestHandler.end_headers(self)

    def send_my_headers(self):
        self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
        self.send_header("Pragma", "no-cache")
        self.send_header("Expires", "0")
        self.send_header("Access-Control-Allow-Origin", "*")


if __name__ == '__main__':
    http.server.test(HandlerClass=MyHTTPRequestHandler)

Then is is a simple matter of :

def visualize(sys, qps):
    port = 8000
    to_render = html.render(sys, qps)
    to_render = to_render.replace(
        "https://cdn.jsdelivr.net/gh/google/brax@a93dadc48a41177a4d9e7794ce17c1ad98ed8583", 
        f"http://127.0.0.1:8000"
    )
    display(HTML(to_render))

@flobotics
Copy link

hi @o-Oscar ,
when i use this, it does not show anything ? The webserver is running, i can access the files with a browser. There are also no error messages ? When i print(f"html>{to_render}<") i can see that the string is replaced correctly, but i cannot see anything ?

You got a hint ?

@namheegordonkim
Copy link
Contributor

FWIW, I've been dumping viewer HTML explicitly using save_html() from html.py, changing the JS import statement to my local viewer.js path, and running viewer.html from a Python simple HTTP server (e.g. python -m http.server). I do agree that it's a bit convoluted though. Would be great to have a native viewer window, as brought up in #47

@EelcoHoogendoorn
Copy link

hi @o-Oscar , when i use this, it does not show anything ? The webserver is running, i can access the files with a browser. There are also no error messages ? When i print(f"html>{to_render}<") i can see that the string is replaced correctly, but i cannot see anything ?

You got a hint ?

Ive got the same issue as described here.

@EelcoHoogendoorn
Copy link

Nevermind, worked after more permutations; not sure which ones

@erikfrey erikfrey added the enhancement New feature or request label Nov 11, 2021
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

5 participants