Skip to main content

Dash components for Gov UK

Project description

UK Gov Dash components

UK Gov Dash components is a Dash component library which provides GOV.UK styled components for:

  • Accordion
  • AutoComplete Dropdown
  • Checklist

⚠️ We intentionally only provide support for Python Dash projects. If you are interested in Julia or R support please contact the team PythonVisualisations@levellingup.gov.uk.

Using the package from Python

For installation using pip:

pip install uk-gov-dash-components

or for a specific version:

pip install uk-gov-dash-components~=6.7.0

For installation into a conda environment, paste the following code into the environment configuration file:

 - pip:
     - uk-gov-dash-components~=6.7.0

Contributing to this package

Plotly Dash have written some documentation on React for Python Developers which acts as good starting point.

Install dependencies

If you have selected install_dependencies during the prompt, you can skip this part.

  1. Install npm packages
    npm install
    
  2. Create conda environment
    conda env create -f environment.yml 
    

Create a new component

Use the ComponentTemplate component as a template. This component is class based, while other components in this repository are functions. You can read more about function components in the React documentation.

  1. Copy src/lib/components/ComponentTemplate.react.js -> src/lib/components/YourComponent.react.js
  2. Copy src/lib/fragments/ComponentTemplate.react.js -> src/lib/fragments/YourComponent.react.js
  3. Modify the newly created files, replacing all references to ComponentTemplate with YourComponent, and replacing the sample functionality with what you'd like.
  4. Add both an import and export of YourComponent to both src/lib/index.js and src/lib/LazyLoader.js
  5. Add YourComponent to the import at the top of the src/demo/App.js file, and add <YourComponent> to the App.render() function.
    1. Run npm start to start the demo server.
    2. Open http://localhost:55555 in your browser.
    3. If nothing apears on the page, then open up the browser console to see the error(s).

Test your code within a Dash Application

If you've previously been running npm start you've been running your component within a pure React environment separate to Dash.

  1. Build your code which will generate all the Python code required
    npm run build
    
  2. Run the example.py sample Dash app:
    python example.py
    
  3. Visit http://localhost:8050 in your web browser
  4. Add your component to example.py using the existing Python as a template.

Write tests for your component.

These are the default instructions

  • A sample test is available in tests/test_example.py, it will load example.py and you can then automate interactions with selenium.
  • Run the tests with pytest tests.
  • The Dash team uses these types of integration tests extensively. Browse the Dash component code on GitHub for more examples of testing (e.g. https://github.com/plotly/dash-core-components)

Add custom styles to your component

These are the default instructions

  • Add custom styles to your component by putting your custom CSS files into your distribution folder (uk_gov_dash_components).
    • Make sure that they are referenced in MANIFEST.in so that they get properly included when you're ready to publish your component.
    • Make sure the stylesheets are added to the _css_dist dict in uk_gov_dash_components/__init__.py so dash will serve them automatically when the component suite is requested.
  • Review your code

Create a production build and publish:

  1. Update the version property of the package.json file in the syle of Major.Minor.Patch, e.g. 1.2.3

    • Major - any breaking changes to previous functionality.
    • Minor - additional functionality that doesn't effect backward compatibility. When updated the patch version should be reset to zero. eg. 2.3.1 goes to 2.4.0 for minor update.
    • Patch - bug fixes that don't effect backward compatibility. For more information see here
  2. Build your code:

    npm run build
    
  3. Create a Python distribution

    python setup.py sdist bdist_wheel
    

    This will create source and wheel distribution in the generated the dist/ folder. See PyPA for more information.

  4. Test your tarball by copying it's full file path and installing it locally into a new environment by running:

    pip install "<full file path>"
    

    eg. pip install "D:\Users\user\Desktop\Source Code Store\gov-uk-dash-react-components\dist\uk_gov_dash_components-1.2.1.tar.gz"

  5. When your PR is merged to main, it will be released automatically by the Release workflow using the version within package.json. You can still merge a PR which doesn't update the version within package.json, but the Release workflow will fail. Failure of the Release workflow means that a new release won't have been generated, the changes made to the package will not have been uploaded to PyPI and you won't be able to use the new version of the code in dashboard repos until you update the version in package.json.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uk_gov_dash_components-1.9.3.tar.gz (85.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uk_gov_dash_components-1.9.3-py3-none-any.whl (90.7 kB view details)

Uploaded Python 3

File details

Details for the file uk_gov_dash_components-1.9.3.tar.gz.

File metadata

  • Download URL: uk_gov_dash_components-1.9.3.tar.gz
  • Upload date:
  • Size: 85.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for uk_gov_dash_components-1.9.3.tar.gz
Algorithm Hash digest
SHA256 b6a2c7bf17c793a9075cda49a63253367d96b033fa0a8f70e722e32418b76ad4
MD5 c72015b8472bd6926a8b85abe027a615
BLAKE2b-256 1d68c31f252cd06b662f951b9ca487fed02c157083e1a863946c1f73cd5d0ac4

See more details on using hashes here.

File details

Details for the file uk_gov_dash_components-1.9.3-py3-none-any.whl.

File metadata

File hashes

Hashes for uk_gov_dash_components-1.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c9cbc31a303403747ed6251bddbe21711271df78fed30557f2be4ec12e255955
MD5 1aca1c39aaf3331fc74aa21066f02b9e
BLAKE2b-256 28581cff0ad568534d135452c8fca53bd406eade4a5015aec6289411d2907881

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page