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

Add param.Bytes mapped to pn.FileInput #2901

Closed
Jhsmit opened this issue Nov 10, 2021 · 1 comment
Closed

Add param.Bytes mapped to pn.FileInput #2901

Jhsmit opened this issue Nov 10, 2021 · 1 comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Milestone

Comments

@Jhsmit
Copy link

Jhsmit commented Nov 10, 2021

I frequently have a set of input parameters in a param.Parameterized class which I expose with pn.Param. Often one of these is a FileInput.
I would like a param.Bytes parameter which maps to a pn.widgets.FileInput by default.

I would like to be able to do:

import param
import panel as pn

class MyApp(param.Parameterized):
    input_file = param.Bytes()

    value_1 = param.Selector(default='a', objects=['a', 'b', 'c'])
    value_2 = param.Integer(3, bounds=(1, 8))

    def __init__(self, **param):
        super().__init__(**param)

        self.markdown = pn.pane.Markdown(object='My markdown',
            width=300)

    @param.depends('input_file', watch=True)
    def _update_mardown(self):
        self.markdown.object = self.input_file.decode()



app = MyApp()
controls = pn.Param(app)
layout = pn.Row(app.markdown, controls)
layout.servable()

Currently I use:

import param
import panel as pn

class MyApp(param.Parameterized):
    input_file = param.Parameter()

    value_1 = param.Selector(default='a', objects=['a', 'b', 'c'])
    value_2 = param.Integer(3, bounds=(1, 8))

    def __init__(self, **param):
        super().__init__(**param)

        self.markdown = pn.pane.Markdown(object='My markdown',
            width=300)

    @param.depends('input_file', watch=True)
    def _update_mardown(self):
        self.markdown.object = self.input_file.decode()



app = MyApp()
controls = pn.Param(app, widgets={'input_file': pn.widgets.FileInput})
layout = pn.Row(app.markdown, controls)
layout.servable()

Desired output:
image

Which shows the contents of the input file as text in the markdown

@maximlt maximlt added the type: enhancement Minor feature or improvement to an existing feature label Nov 11, 2021
@maximlt
Copy link
Member

maximlt commented Nov 11, 2021

There's an open PR in param that adds a Bytes Parameter (holoviz/param#542) which I guess could be mapped to a FileInput in param.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants