Giter Club home page Giter Club logo

dash-typescript-component-template's Introduction

Dash TypeScript Component Template

This repository contains a Cookiecutter template to create your own Dash components with TypeScript.

Usage

To use this template:

  1. Install the requirements:
    pip install cookiecutter
    NodeJS is also required, install nvm to get the appropriate node version.
  2. Run cookiecutter on the template repo:
    cookiecutter gh:plotly/dash-typescript-component-template
  3. Answer the questions about the project.
    • project_name: This is the "human-readable" name of your project. For example, "Dash Core Components".
    • project_shortname: is derived from the project name, it is the name of the "Python library" for your project. By default, this is generated from your project_name by lowercasing the name and replacing spaces & - with underscores. For example, for "Dash Core Components" this would be "dash_core_components".
    • component_name: This is the name of the initial component that is generated. As a JavaScript class name it should be in PascalCase. defaults to the PascalCase version of project_shortname.
    • jl_prefix: Optional prefix for Julia components. For example, dash_core_components uses "dcc" so the Python dcc.Input becomes dccInput in Julia, and dash_table uses "dash" to make dashDataTable.
    • r_prefix: Optional prefix for R components. For example, dash_core_components uses "dcc" so the Python dcc.Input becomes dccInput in R, and dash_table uses "dash" to make dashDataTable.
    • author_name and author_email: for package.json and DESCRIPTION (for R) metadata.
    • github_org: If you plan to push this to GitHub, enter the organization or username that will own it (for URLs to the project homepage and bug report page)
    • description: the project description, included in package.json.
    • license: License type for the component library. Plotly recommends the MIT license, but you should read the generated LICENSE file carefully to make sure this is right for you.
    • publish_on_npm: Set to false to only serve locally from the package data.
  4. The project will be generated in a folder named with your project_shortname.
  5. Follow the directions in the generated README to start developing your new Dash component.

More Resources

dash-typescript-component-template's People

Contributors

gvwilson avatar jordan-hall avatar snehilvj avatar t4rk1n avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dash-typescript-component-template's Issues

Python class not being generated

Even after npm build run, the python class is not being generated in the example_component directory. I can see the example_component.js file but no ExampleComponent.py . How to import the React component and run the python dash application?

Components which have props with hyphens generate a syntax error in Python

When converting components which have props containing a hyphen, e.g. "aria-expanded", the generated Python class has "area-expander" in its parameters, which throws an invalid syntax error.

def __init__(self, children=None, value=Component.REQUIRED, aria-expanded=Component.UNDEFINED, **kwargs):
        self._prop_names = ['children', 'id', 'about', 'accessKey', 'aria-expanded', ]

SyntaxError: invalid syntax

Fonts - dash.exceptions.DependencyException: app is registered but the path requested is not valid.

I'm using this template to bridge https://primereact.org/multiselect/ into Dash but I'm running into issues with Icons not showing:

Screenshot 2023-02-20 at 11 48 22

There's a reproducible example here: https://github.com/gofford/dash-primereact-app.

What I've found so far: the JS Console yields a series of 500 errors for the resource files corresponding to the icons (see [1]), but the files do appear to be available [2]. If I navigate directly to the expected path of the resource (from the stylesheet [3]), I get a DependencyException [4].

I have built this same component in JS using the "normal" cookiecutter template and the icons appear OK, but I need to use TS so that this component can co-exist with other components that have been built from scratch in TS.

Do you know how to remedy this, or if theres anything that I need to do differently during the build or in the webpack?

Figures

[1] 500 Error codes Screenshot 2023-02-20 at 11 48 28
[2] Files appear to exist Screenshot 2023-02-20 at 11 48 34
[3] Stylesheet URLs Screenshot 2023-02-20 at 12 06 13
[4] DependencyException ``` DependencyException dash.exceptions.DependencyException: "dash_primereact_app" is registered but the path requested is not valid. The path requested: "d44157bdfa026dc877af.eot" List of registered paths: defaultdict(, {'dash': {'dcc/dash_core_components-shared.js', 'html/dash_html_components.min.js', 'dcc/async-slider.js', 'html/dash_html_components.min.js.map', 'dcc/async-markdown.js', 'dcc/async-highlight.js', 'dcc/async-datepicker.js', 'dcc/dash_core_components-shared.js.map', 'dcc/async-mathjax.js', 'dcc/async-dropdown.js', 'dcc/async-mathjax.js.map', 'dash_table/async-highlight.js.map', 'dash_table/async-export.js.map', 'dcc/async-highlight.js.map', 'dash-renderer/build/dash_renderer.dev.js.map', 'dcc/async-dropdown.js.map', 'dash_table/bundle.js', 'dash_table/bundle.js.map', 'dcc/async-upload.js.map', 'dcc/async-datepicker.js.map', 'dash_table/async-highlight.js', 'dcc/dash_core_components.js.map', 'dcc/async-plotlyjs.js', 'deps/[email protected]', 'dcc/plotly.min.js', 'deps/[email protected]', 'dcc/async-graph.js', 'deps/[email protected]', 'dash_table/async-table.js.map', 'dash_table/async-table.js', 'dcc/async-plotlyjs.js.map', 'dcc/async-graph.js.map', 'dcc/async-slider.js.map', 'dcc/async-upload.js', 'dcc/async-markdown.js.map', 'deps/[email protected]', 'dash-renderer/build/dash_renderer.dev.js', 'dcc/dash_core_components.js', 'dash_table/async-export.js'}, 'dash_primereact_app': {'dash_primereact_app.js.map', 'dash_primereact_app.js'}}) ```

Async option

In the "normal" (i.e. non-async) component template, there is an async option. Could a similar options be added to this repo?

Possible to pick from `React.HTMLAttributes`?

When making a Dash component based on existing React TS component, it would be useful to be able to extend the component's interface instead of specifying each prop anew.

I believe this should work in principle but in practice when I try to inherit from the underlying component's interface, the result is an empty object.

Consider this dummy component:

import React from 'react'
import { DashComponentProps } from '../props'

type Props = {
    /**
     * Variant is the name of a variation of the button so that buttons can vary very variably.
     */
    variant: 'yellow' | 'green';
}
    & DashComponentProps
    & React.ButtonHTMLAttributes<HTMLButtonElement>  // <--- this is the problematic line


const Button = (props: Props) => {
    props.variant = "green"
    props.title = "foo bar"
    return <button {...props}>{props.children}</button>
}

Button.defaultProps = {}
export default Button

Building (yarn build) produces a Button class in Button.py with zero attributes. ๐Ÿ˜ฑ

I have traced the issue to props = getPropInfo(propsType, defaultProps) line in extract-meta.js, but I'm kind of out of my depth WRT Typescript here.

My plan was to pick a few props from the original interface. For example, autofocus:

    & DashComponentProps
    & Pick<React.ButtonHTMLAttributes<HTMLButtonElement>, 'autoFocus'>

I was expecting this to add a autoFocus?: boolean | undefined; to the Prop type, but what I actually get from getPropInfo in extract-meta.js at that point is:

Notification_Center

I would expect something like "type": {"name": "bool", "raw": "boolean"}
instead of "type":{"name": "shape", "value": Object, "raw": "ButtonHTMLAttributes<HTMLButtonElement>"}

Or am I doing something terribly wrong here?

`npm run build` failing: "sh: dash-generate-components: command not found"

I followed the usage instructions step by step using all default values. And then in the generated project followed the README there, but npm run build fails with "sh: dash-generate-components: command not found".

Commands run:

python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
npm install
npm run build

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.