Panel: Ensure pn.serve validates keywords

Created on 24 Aug 2020  路  3Comments  路  Source: holoviz/panel

ALL software version info

The current master branch of Panel (0.10.0a23.post4+g0fe6e23) installed via

pip install -e git+https://github.com/holoviz/panel.git#egg_name=master

Description of expected behavior and the observed behavior

I would expect to be able to use something like

pn.serve(
    {"": app},
    static_dics={"__target__": "./__target__"}
)

and be able to see the files in __target__ served.

But I'm not.

Complete, minimal, self-contained example code that reproduces the issue

You will additionally need to pip install transcrypt.

Create the file p5test.py

import math
def p_setup_gen(p):

  #--- p5 setup() function --------------------------
  def p_setup():
    p.createCanvas(200, 200)
    p.background(160)

  return p_setup

def p_draw_gen(p):

  #--- p5 draw() function ---------------------------
  def p_draw():
    p.fill('blue')
    fc = p.frameCount
    p.background(200)
    r = math.sin(fc/60) *50 + 50
    p.ellipse(100,100,r,r)

  return p_draw

def sketch_setup(p):
  p.setup = p_setup_gen(p)
  p.draw  = p_draw_gen(p)

myp5 = __new__ (p5(sketch_setup, 'sketch-holder'))

run transcrypt -n p5test.py and verify you get a subfolder __target__ that looks like

image

Create the file app.py

import panel as pn
import pathlib

pn.config.js_files.update({
    "p5": "https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js",
})

def app():
    source_path_or_url = pathlib.Path(__file__).parent/"__target__/p5test.js"
    source_js = "" # source_path_or_url.read_text()

    HTML = f"""
    "Hello"
    <div id="sketch-holder">
        <!-- Our sketch will go here! -->
    </div>
    <script type="module" src="__target__/p5test.js"></script>
    """

    return pn.pane.HTML(HTML)

pn.serve(
    {"": app},
    static_dics={"__target__": "./__target__"}
)

run python app.py and inspect the console errors

image

and the sources

image

Additional Context

According to https://github.com/holoviz/panel/pull/1319 support for static files should have been added.

If you want to see the example in action you can via

p5test.html

```html

````

python -m http.server 8000 and navigate to http://localhost:8000/p5test.html

p5js

bug

All 3 comments

Fixed by changing static_dics to static_dirs :-)

An error message from Panel would have been helpful.

image

Will close this one.

Reopened and repurposed, I'm surprised you saw no warning or error at all.

Seems difficult, the kwargs are just passed down to bokeh's Server which passes it down to tornado.web.TornadoApplication.

Was this page helpful?
0 / 5 - 0 ratings