dash-uploader icon indicating copy to clipboard operation
dash-uploader copied to clipboard

How to center the progress percentage?

Open KelSolaar opened this issue 2 years ago • 10 comments

Hi,

I was wondering if there is a canonical way to center the progress percentage?

image

Cheers,

Thomas

KelSolaar avatar Mar 22 '22 10:03 KelSolaar

Which version of dash-uploader you are using?

fohrloop avatar Mar 22 '22 10:03 fohrloop

Hi @np-8,

dash                      2.3.0
dash-bootstrap-components 1.0.3
dash-core-components      2.0.0
dash-html-components      2.0.0
dash-renderer             1.9.1
dash-table                5.0.0
dash-uploader             0.6.0

Cheers,

Thomas

KelSolaar avatar Mar 22 '22 10:03 KelSolaar

Interesting. Here are few screenshots where the percentage seems to be centered.

Could you paste here some code that reproduces this behaviour?

fohrloop avatar Mar 22 '22 11:03 fohrloop

I cannot post the entire app because the repository is currently private (will make public soon) but the code where I use Upload is a follows:

_LAYOUT_COLUMN_OPTIONS_CHILDREN = [
    Div(
        Upload(
            id=_uid("idt-archive-upload"),
            text="Click or drop an IDT Archive here to upload!",
            max_file_size=4096,
            filetypes=["zip"],
            upload_id=uuid.uuid1(),
        ),
        style={
            "textAlign": "center",
            "width": "100%",
            "display": "inline-block",
        },
    ),

# Lot of stuff ...
# Lot of stuff ...
# Lot of stuff ...

LAYOUT = Container(
    [
        H3([Link(APP_NAME, href=APP_PATH)]),
        Main(
            Tabs(
                [
                    Tab(
                        Row(
                            [
                                Col(
                                    _LAYOUT_COLUMN_ILLUMINANT_CHILDREN,
                                    width=3,
                                ),
                                Col(
                                    [
                                        Row(
                                            Col(
                                                _LAYOUT_COLUMN_OPTIONS_CHILDREN,
                                            ),
                                        ),
                                        Row(
                                            Col(
                                                _LAYOUT_COLUMN_IDT_COMPUTATION_CHILDREN,  # noqa
                                            ),
                                        ),
                                    ],
                                    width=9,
                                ),
                            ]
                        ),
                        label="Computations",
                        className="mt-3",
                    ),

# Lot of stuff ...
# Lot of stuff ...
# Lot of stuff ...

KelSolaar avatar Mar 23 '22 07:03 KelSolaar

I could not make you script to run, but I'm thinking if there is some css styling that overrides the defaults and makes the percentage not centered.

Could you try to create app2.py to the side of your app.py with following contents and see if the percentage is centered?

import uuid

import dash_uploader as du
import dash
import dash_html_components as html
from dash.dependencies import Output

app = dash.Dash(__name__)

UPLOAD_FOLDER_ROOT = r"C:\tmp\Uploads"
du.configure_upload(app, UPLOAD_FOLDER_ROOT)


def get_upload_component(id):
    return du.Upload(
        id=id,
        max_file_size=1800,  # 1800 Mb
        filetypes=["csv", "zip"],
        upload_id=uuid.uuid1(),  # Unique session id
    )


def get_app_layout():

    return html.Div(
        [
            html.H1("Demo"),
            html.Div(
                [
                    get_upload_component(id="dash-uploader"),
                    html.Div(id="callback-output"),
                ],
                style={  # wrapper div style
                    "textAlign": "center",
                    "width": "600px",
                    "display": "inline-block",
                },
            ),
        ],
        style={
            "textAlign": "center",
        },
    )


# get_app_layout is a function
# This way we can use unique session id's as upload_id's
app.layout = get_app_layout


@du.callback(
    output=Output("callback-output", "children"),
    id="dash-uploader",
)
def get_a_list(filenames):
    return html.Ul([html.Li(filenames)])


if __name__ == "__main__":
    app.run_server(debug=True)

fohrloop avatar Mar 23 '22 07:03 fohrloop

If that does not work, see if you have .css files in an assets folder that gets loaded, which could potentially change how the component looks like. Also, you could check with browser debug tools (F12 on Chrome) the properties of the component. Are they different than this (right click on the percentage -> Inspect). It is easier to inspect if you enable the pause button first.

image

.progress-value class is responsible for the positioning of the percentage. See if you import any css that alters this. I think this should be called something like .dash-uploader-progress-value in the future to prevent clashes.

fohrloop avatar Mar 23 '22 07:03 fohrloop

As a fix, you could try to add to your custom css this:

#dash-uploader span.progress-value {
    position: absolute !important;
    right: 0px !important;
    left: 0px !important;
}

Replace #dash-uploader with the du.Upload component id if you have changed it. The css code is inserted to any .css file in the assets folder. So, if your app is located at C:\somefolder\app.py, you should add the css code to C:\somefolder\assets\somestyle.css.

fohrloop avatar Mar 23 '22 07:03 fohrloop

Thanks I will try! The pause button is super useful here :) In the meantime, here is a screengrab, the CSS seems to be correct:

image

KelSolaar avatar Mar 23 '22 08:03 KelSolaar

If the css is correct, then I would assume that there is something around the component that interferes with it.

Try if you could find a minimal example that reproduces the problem. Perhaps, try disabling bootstrap (or other additional css). That would help to pinpoint the problem. Also, you could try to reproduce the problem in the app I posted above, by adding there components from your app.

fohrloop avatar Mar 23 '22 08:03 fohrloop

Hi @np-8,

Sorry for not getting back to you before, so it indeed seems like to be related to dash_bootstrap_components:

image

Here is some code to reproduce the issue:

import uuid

import dash_uploader as du
import dash
from dash import html
import dash_bootstrap_components
from dash.dependencies import Output
from dash_bootstrap_components import Col, Container, Row

app = dash.Dash(
    __name__, external_stylesheets=[dash_bootstrap_components.themes.DARKLY]
)

UPLOAD_FOLDER_ROOT = r"/private/var/folders/xr/sf4r3m2s761fl25h8zsl3k4w0000gn/T/Uploads"
du.configure_upload(app, UPLOAD_FOLDER_ROOT)


def get_upload_component(id):
    return du.Upload(
        id=id,
        max_file_size=4096,  # 1800 Mb
        filetypes=["csv", "zip"],
        upload_id=uuid.uuid1(),  # Unique session id
        pause_button=True,
    )


def get_app_layout():

    return Container(
        Row(
            [
                Col(html.H3("Col 3")),
                Col(
                    html.Div(
                        [
                            get_upload_component(id="dash-uploader"),
                            html.Div(id="callback-output"),
                        ],
                        style={  # wrapper div style
                            "textAlign": "center",
                            "width": "100%",
                            "display": "inline-block",
                        },
                    )
                ),
            ]
        ),
    )


# get_app_layout is a function
# This way we can use unique session id's as upload_id's
app.layout = get_app_layout


@du.callback(
    output=Output("callback-output", "children"),
    id="dash-uploader",
)
def get_a_list(filenames):
    return html.Ul([html.Li(filenames)])


if __name__ == "__main__":
    app.run_server(debug=True)

KelSolaar avatar Apr 04 '22 07:04 KelSolaar