Traceback (most recent call last):
File "/app/smb_shares/python_lib/ppds/ppds_dash/dashboard.py", line 410, in copy_to_clipboard
pd.DataFrame(data).to_clipboard()
File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/util/_decorators.py", line 333, in wrapper
return func(*args, **kwargs)
File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/core/generic.py", line 3241, in to_clipboard
clipboards.to_clipboard(self, excel=excel, sep=sep, **kwargs)
File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/io/clipboards.py", line 178, in to_clipboard
clipboard_set(text)
File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/io/clipboard/__init__.py", line 659, in lazy_load_stub_copy
return copy(text)
File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/io/clipboard/__init__.py", line 316, in __call__
raise PyperclipException(EXCEPT_MSG)
pandas.errors.PyperclipException:
Pyperclip could not find a copy/paste mechanism for your system.
For more information, please visit
https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error
На сервере, но это ничего не изменило - ошибка все равно есть. Насколько я вижу, панды не поддерживают кроссплатформенное копирование. Или, может быть, я что-то упускаю?
Моим следующим шагом было просмотреть сборку Dash в dcc.clipboard.
#%%
import dash
from dash import dcc, html, Input, Output, State
import pandas as pd
# Initialize the Dash app
app = dash.Dash(__name__)
# Sample function to generate a DataFrame (can be customized)
def generate_dataframe():
# You can customize this function to generate any DataFrame
df = pd.DataFrame({
'A': [1, 2, 3],
'B': [4, 5, 6]
})
return df.to_csv(index=False)
# App Layout
app.layout = html.Div([
# Button to trigger the DataFrame generation and copy action
html.Button("Generate and Copy DataFrame", id="generate-copy-button", n_clicks=0),
# Hidden TextArea to store the DataFrame content before copying
dcc.Textarea(
id="data-text",
style={"display": "none"}, # Hidden TextArea
value="" # Initially empty
),
# Clipboard component to copy the content
dcc.Clipboard(
target_id="data-text", # Targeting the hidden TextArea
title="Copy to clipboard",
id="clipboard",
style={"display": "none"} # Hidden, since the button triggers it
),
# Message to display after copying
html.P(id="copy-message", style={"color": "green", "fontWeight": "bold"})
])
# Callback to generate the DataFrame and copy it to clipboard when the button is clicked
@app.callback(
[Output("data-text", "value"), # Update the TextArea with the DataFrame content
Output("copy-message", "children"), # Update the message after copying
Output("clipboard", "n_clicks")], # Trigger the clipboard component
[Input("generate-copy-button", "n_clicks")], # Button click input
prevent_initial_call=True
)
def generate_and_copy(n_clicks):
# Generate DataFrame content
df_content = generate_dataframe()
# Update the message
copy_message = "DataFrame content copied to clipboard!"
# Trigger the clipboard action by setting n_clicks to 1
return df_content, copy_message, 1
if __name__ == '__main__':
app.run(port=8041,debug=True)
# %%
В этом примере он работает с сервера Linux -> клиент Linux, но не сервер Linux -> клиент Windows (в буфер обмена ничего не помещается)
У кого-нибудь получилось создать Linux-сервер Dash, на котором можно копировать в буфер обмена клиента Windows? Я пробовал: [code]pd.DataFrame(data).to_clipboard() [/code] это дает [code] Traceback (most recent call last): File "/app/smb_shares/python_lib/ppds/ppds_dash/dashboard.py", line 410, in copy_to_clipboard pd.DataFrame(data).to_clipboard() File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/util/_decorators.py", line 333, in wrapper return func(*args, **kwargs) File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/core/generic.py", line 3241, in to_clipboard clipboards.to_clipboard(self, excel=excel, sep=sep, **kwargs) File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/io/clipboards.py", line 178, in to_clipboard clipboard_set(text) File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/io/clipboard/__init__.py", line 659, in lazy_load_stub_copy return copy(text) File "/app/smb_shares/python_env/pyenv/versions/3.10.12/envs/base_3.10.12/lib/python3.10/site-packages/pandas/io/clipboard/__init__.py", line 316, in __call__ raise PyperclipException(EXCEPT_MSG) pandas.errors.PyperclipException: Pyperclip could not find a copy/paste mechanism for your system. For more information, please visit https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error [/code] Я пытался установить [code]sudo apt-get install xclip [/code] На сервере, но это ничего не изменило - ошибка все равно есть. Насколько я вижу, панды не поддерживают кроссплатформенное копирование. Или, может быть, я что-то упускаю? Моим следующим шагом было просмотреть сборку Dash в dcc.clipboard. [code]#%% import dash from dash import dcc, html, Input, Output, State import pandas as pd
# Initialize the Dash app app = dash.Dash(__name__)
# Sample function to generate a DataFrame (can be customized) def generate_dataframe(): # You can customize this function to generate any DataFrame df = pd.DataFrame({ 'A': [1, 2, 3], 'B': [4, 5, 6] }) return df.to_csv(index=False)
# App Layout app.layout = html.Div([ # Button to trigger the DataFrame generation and copy action html.Button("Generate and Copy DataFrame", id="generate-copy-button", n_clicks=0),
# Hidden TextArea to store the DataFrame content before copying dcc.Textarea( id="data-text", style={"display": "none"}, # Hidden TextArea value="" # Initially empty ),
# Clipboard component to copy the content dcc.Clipboard( target_id="data-text", # Targeting the hidden TextArea title="Copy to clipboard", id="clipboard", style={"display": "none"} # Hidden, since the button triggers it ),
# Message to display after copying html.P(id="copy-message", style={"color": "green", "fontWeight": "bold"}) ])
# Callback to generate the DataFrame and copy it to clipboard when the button is clicked @app.callback( [Output("data-text", "value"), # Update the TextArea with the DataFrame content Output("copy-message", "children"), # Update the message after copying Output("clipboard", "n_clicks")], # Trigger the clipboard component [Input("generate-copy-button", "n_clicks")], # Button click input prevent_initial_call=True ) def generate_and_copy(n_clicks): # Generate DataFrame content df_content = generate_dataframe()
# Update the message copy_message = "DataFrame content copied to clipboard!"
# Trigger the clipboard action by setting n_clicks to 1 return df_content, copy_message, 1
if __name__ == '__main__': app.run(port=8041,debug=True)
# %% [/code] В этом примере он работает с сервера Linux -> клиент Linux, но не сервер Linux -> клиент Windows (в буфер обмена ничего не помещается)