Programmatically create a React component from Python

Hello,

I have a question and hope that you have some ideas on this.

Say you want to shift was much coding as possible towards the Python part of
Streamlit and do as little as possible on the JavaScript, React side of a Custom Component.

I am thinking about if it would be possible to have something like a generic custom component
that could morph into any React component just by the parameters you are injecting
from the Python side. But I am not sure if this is feasible at all.

Something like

import generic_custom_component

attr = {}
attr["autoComplete"] = True
attr["style"] = 'some css here'
attr["disabled"]="{this.props.disabled}"
attr["onChange"] = "some code here"
attr["render_func"] = """
      <span>
        Hello, {name}! &nbsp;
        <button
          style={style}
          onClick={this.onClicked}
          disabled={this.props.disabled}
          onFocus={this._onFocus}
          onBlur={this._onBlur}
        >
          Click Me!
        </button>
      </span>
"""


result = generic_custom_component(type="TextInput",
                                  name="Streamlit",
                                  attr=attr)


What are your thoughts about this?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.