예제 #1
0
def ComponentReference(component_name, lib=dcc):
    component = getattr(lib, component_name)
    component_doc = component.__doc__

    return_div = [
        Markdown("""
            > Access this documentation in your Python terminal with:
            > ```python
            > >>> help({}.{})
            > ```
            """.format(lib.__name__, component_name) + """
            > Our recommended IDE for writing Dash apps is Dash Enterprise's
            > [Data Science Workspaces](https://plotly.com/dash/workspaces),
            > which has typeahead support for Dash Component Properties.
            > [Find out if your company is using
            > Dash Enterprise](https://go.plotly.com/company-lookup).
            """ if not tools.is_in_dash_enterprise() else "")
    ]

    docs = component_doc.split("Keyword arguments:")[-1]

    # This check for the old style docstrings built with dash<=1.18.1
    if docs.count("\n\n-") < 2:
        return format_old_style_docstrings(component_doc, return_div)

    # formats code blocks that includes square brackets
    docs = docs.replace("[", "\[").replace("]", "\]")
    verbatim_regex = r"`((\\\[)((.|\n)*?)(\\\]))`"
    docs = re.sub(re.compile(verbatim_regex), r"`[\3]`", docs)

    # format links
    link_regex = r"\\\[([\w\.\-:\s\/]+)\\\]\(([\w\.\-:#\/]+)\)"
    docs = re.sub(re.compile(link_regex), r"[\1](\2)", docs)

    # formats the prop defaults
    prop_optional_default_regex = r"""default (.*)\)"""
    docs = re.sub(re.compile(prop_optional_default_regex), r"default `\1`)",
                  docs)

    # formats the prop type
    prop_type_regex = r"""(\s*- \w+?\s*\()([^;]*);"""
    docs = re.sub(re.compile(prop_type_regex), r"\1*\2*;", docs)

    # formats the prop name on first level only
    prop_name_regex = r"""(\n- )(\w+?) \("""
    docs = re.sub(re.compile(prop_name_regex), r"\1**`\2`** (", docs)

    # formats keys of nested dicts
    nested_prop_name_regex = r"""(\n\s+- )(\w+?) \("""
    docs = re.sub(re.compile(nested_prop_name_regex), r"\1**`\2`** (", docs)

    # removes a level of nesting
    docs = docs.replace("\n-", "\n")

    return_div.append(Markdown(docs))
    return html.Div(return_div, className="reference")
예제 #2
0
파일: index.py 프로젝트: rreusser/dash-docs
# coding=utf-8
import dash_html_components as html
from dash_docs import reusable_components as rc
import dash_core_components as dcc
from dash_docs import tools
import os

content = tools.load_markdown_files(__file__)
check_url = tools.is_in_dash_enterprise()

PAGE_CONTENT = rc.Markdown(
    '''

{setup}

'''.format(**{k.replace('.md', ''): v
              for (k, v) in content.items()}).format(
                  graphql_api=('[GraphQL API Docs](/Docs/app-manager-api)'
                               if check_url else 'GraphQL API Docs'),
                  graphql_api_notes=('' if check_url else '''
> **To view the GraphQL API Docs**, visit: https://<your-dash-enterprise-hostname\>/Docs/app-manager-api,
> replacing <your-dash-enterprise-hostname\> with the hostname of your licensed
> Dash Enterprise in your VPC. [Look up the hostname for your company’s license](https://go.plotly.com)
''')))

layout = html.Div([
    html.H1('Dash Enterprise Continuous Integration'),
    html.Div(''),
    html.Div([PAGE_CONTENT]),
])
예제 #3
0
파일: index.py 프로젝트: rreusser/dash-docs
    `dash_core_components` and the `dash_html_components` library
    but you can also [build your own](https://github.com/plotly/dash-component-boilerplate)
    with JavaScript and React.js.

    Note: Throughout this documentation, Python code examples are meant to
    be saved as files and executed using `python app.py`.
    You can also use Jupyter with the [JupyterDash](https://github.com/plotly/jupyter-dash) library.
    '''),

    rc.Markdown('''

    > If you're using Dash Enterprise's [Data Science Workspaces](https://plotly.com/dash/workspaces),
    > copy & paste the below code into your Workspace ([see video](https://plotly.com/dash/workspaces/#screencast)).
    > _[Find out if your company is using Dash Enterprise](https://go.plotly.com/company-lookup)_

    ''') if not tools.is_in_dash_enterprise() else '',

    rc.Markdown('''
    To get started, create a file named `app.py` with the following code.

    Then, run the app with

    ```
    $ python app.py
    ...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
    ```

    and visit [http://127.0.0.1:8050/](http://127.0.0.1:8050/)
    in your web browser. You should see an app that looks like this.
    '''),
예제 #4
0
def ComponentReference(component_name, lib=dcc):
    component = getattr(lib, component_name)
    component_doc = component.__doc__

    regex = r'''^([^\(]*)\s*\(([^;]*);\s*(.+?)\):\s*(.*?)\s*$'''

    return_div = [
        Markdown('''
            > Access this documentation in your Python terminal with:
            > ```python
            > >>> help({}.{})
            > ```
            '''.format(lib.__name__, component_name) + '''
            > Our recommended IDE for writing Dash apps is Dash Enterprise's
            > [Data Science Workspaces](https://plotly.com/dash/workspaces),
            > which has typeahead support for Dash Component Properties.
            > [Find out if your company is using
            > Dash Enterprise](https://go.plotly.com/company-lookup).
            ''' if not tools.is_in_dash_enterprise() else '')
    ]

    props = component_doc.split('\n-')[1:]

    # sort alphabetically, but keep id at the top
    id_prop = props.pop(0)
    props.sort(key=lambda x: x.strip()[0])
    props = [id_prop] + props

    for prop in props:

        r = re.match(re.compile(regex), prop.replace('\n', ' '))

        if r is None:
            return_div.append(Markdown(dedent(prop.replace('\n', ' '))))
            continue

        (prop_name, prop_type, prop_optional_default, prop_desc) = r.groups()
        prop_desc = prop_desc.replace('[', '\[').replace(']', '\]')

        verbatim_regex = r'`((\\\[)(.*?)(\\\]))`'

        prop_desc = re.sub(re.compile(verbatim_regex), r'`[\3]`', prop_desc)

        link_regex = r'\\\[([\w\.\-:\/]+)\\\]\(([\w\.\-:#\/]+)\)'

        prop_desc = re.sub(re.compile(link_regex), r'[\1](\2)', prop_desc)

        if 'dict containing keys' in prop_desc or 'dicts containing keys' in prop_desc:
            regex_dict = r'''(.*?\.* *[\w]* has the following type: (?:[\w\s|]*)dict[s]* containing keys )([\w\s',]*)(\. Those keys have the following types: )(.*)'''
            parsed_dict_desc = re.match(re.compile(regex_dict), prop_desc)
            try:
                top_level_desc = parsed_dict_desc.groups(0)[0]
                top_level_keys = parsed_dict_desc.groups(0)[1]
                top_level_type_preamble = parsed_dict_desc.groups(0)[2]
                key_defs = parsed_dict_desc.groups(0)[3]

                top_level_keys_list = [
                    key.strip().strip('\'')
                    for key in top_level_keys.split(',')
                ]
                for key in top_level_keys_list:
                    key_defs = key_defs.replace('- {}'.format(key),
                                                '\n- `{}`'.format(key), 1)

                top_level_type_preamble = top_level_type_preamble.replace(
                    'Those keys have the following types: ',
                    'Those keys have the following types: \n')
                prop_desc = top_level_desc + \
                    top_level_keys + \
                    top_level_type_preamble + \
                    ''.join(key_defs)

            except AttributeError:
                pass

        defined_default_val = re.search(r'''default (.*)''',
                                        prop_optional_default)

        prop_optional = prop_optional_default
        if defined_default_val is not None:
            default_val = defined_default_val.groups(1)[0]
            prop_optional = 'default `{}`'.format(default_val)

        if prop_type:
            prop_type = '*{}*; '.format(prop_type)
            prop_type = prop_type.replace('|', '*|*')

        return_div.append(
            Markdown('''**`{}`** ({}{}): {}'''.format(prop_name, prop_type,
                                                      prop_optional,
                                                      prop_desc)))

    return html.Div(return_div, className='reference')
예제 #5
0
    rc.Markdown("""
    ```shell
    pip install dash
    ```
    """,
                style=styles.code_container),
    html.Br(),
    rc.Markdown("""
    This brings along three component libraries
    that make up the core of Dash: `dash_html_components`, `dash_core_components`,
    `dash_table`, as well as the `plotly` graphing library. These libraries are
    under active development, so install and upgrade frequently.

    These docs are running `dash` version `{}`.
    Python 2 and 3 are supported.

    We also recommend installing [Pandas](https://pandas.pydata.org/), which is
    required by [Plotly Express](https://plotly.com/python/plotly-express/) and
    used in many of our examples.
    """.format(dash.__version__)),
    rc.Markdown("""
    ```shell
    pip install pandas
    ```
    """,
                style=styles.code_container),
    html.Hr(),
    rc.WorkspaceBlurb if not tools.is_in_dash_enterprise() else "",
    rc.Markdown("Ready? Now, let's [make your first Dash app](/layout)."),
])