Copy to clipboard in client system

Hi friends! I need your help
I made an app for my colleagues, in one part of this app generates python dict with data
what i need is to make “copy to clipboard” mechanism, i’v made it with pyperclip, but it works only lockaly, doesn’t work on server =(

according to this: https://www.odoo.com/forum/help-1/question/using-pyperclip-to-copy-a-field-text-content-to-clipboard-in-client-system-81362 - i have to make some js code inside my script, but i’m not familiar with js

import dash
import dash_html_components as html

my_dict = {'abc': 123}

app = dash.Dash()
app.layout = html.Div([
    html.Button('copy', id='button')
])

if __name__ == '__main__':
    app.run_server()

what should i do next, to copy my_dict to clipboard?

PS: sorry for my poor English

4 Likes

I need the same feature…

Any updates on this? It would be an awesome feature

hi @jorge243
I took the following example from the clipboard section of the docs. Is this what you’re looking for?

from dash import Dash, dcc, html

app = Dash(__name__)

code = """```
{'abc': 123}
```"""

app.layout = html.Div([
    dcc.Markdown(
        code,
        id='code'
    ),
    dcc.Clipboard(
        target_id="code"
    ),
])


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

Hi Adam! I was actually looking for a way to allow the client to paste data TO the server (e.g. to use df.from_clipboard()). Of course, this works only when testing on local computer, but fails when deploying app (e.g. heroku).

Hi @jorge243

Yes you can copy to the clipboard by updating the content prop in a callback. You can see the Updating the clipboard text in a callback example in the docs.