Hide Export Button if DataTable is Empty

Hi @ims

You can style the Export button by updating the css property of the DataTable in a callback. See the example below.

Soon, you will be able to update the text and the classname of the Export button. This great pull request from a community member @jwbargsten is very close to the finishline: added className and text properties to DataTable to style export button by jwbargsten · Pull Request #799 · plotly/dash-table · GitHub

import dash
import dash_table
import pandas as pd

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/solar.csv")

app = dash.Dash(__name__)

app.layout = dash_table.DataTable(
    id="table",
    columns=[{"name": i, "id": i} for i in df.columns],
    filter_action="native",
    export_format="xlsx",
    data=df.to_dict("records"),
)


@app.callback(
    Output("table", "css"), Input("table", "derived_virtual_data"),
)
def style_export_button(data):
    if data == []:
        return [{"selector": ".export", "rule": "display:none"}]
    else:
        return [{"selector": ".export", "rule": "display:block"}]


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