Copypaste issue (pyperclip 1.8.1)

Hi,

This is my first shared app and everything works fine except when you click on st.button which invokes to pyperclip module.

It appears the following error:

I assume I have to install xclip or something similar but I don’t know from where I can do that.

Any help much appreciated.

Hi @VerbisAnimae, welcome to the Streamlit community!

In order to install system packages on Streamlit sharing, you can create a packages.txt file:

Best,
Randy

Sorry for the late response @randyzwitch.

Thank you so much for your help. I tried and it worked. :slightly_smiling_face:

1 Like

I have a related issue with pyperclip 1.8.2. A streamlit app should use a clipped text from a window, using

text=pyperclip.paste()

It works on the machine running streamlit run. But if the http server is accessed from a different machine, it still pastes the old clipboard. How could pyperclick paste the clipboard of the remote computer?

I guess that won’t work like that because Streamlit only works via browser APIs.

Hi @randyzwitch,

Thank you, for your answer. But I have an exactly same problem while deploying the app (which works fine on my ubuntu machine) to Streamlit Cloud.

I have included the following in the packages.text. I checked on my machine I have libgtk version v3.24.20. The following are necessary for pyperclip

xclip
libgtk-3-dev

Is there any working example that you could share with me? I might be able to spot if I did something wrong here.

Thank you.

cc: @VerbisAnimae

On Streamlit Cloud, your Python app runs in the Cloud and you visualize your Streamlit app on your browser. Those are two separate machines. Calling any copy/paste will run in the Cloud and not have access to the browser’s clipboard.
You’ll probably need a mix of:

to send data from your browser using the Clipboard API, back to the Python app in the Cloud using the Components API.

Hope this helps kickstart a solution,
Fanilo

3 Likes

Thank you. I will try it when I have some time. For now I just skipped using the copy-to-clipboard functionality.

But this surely seems like a cool and useful functionality, that perhaps if Streamlit supports directly, would be awesome.

Hi @andfanilo @randyzwitch

I seem to be having a similar issue just with copy. Here is the simple code snippet in my program (the only difference may be that I have some unicode text in the part being copied:

\quote
toShare = ‘Correct :white_check_mark:
st.code(toShare)
if st.button(‘दवंडी पिटा’):
pyperclip.copy(toShare)
\endquote

I have included pyperclip in requirements
and also xsel and xclip in packages.txt

But that does not seem to help and I still get the no copy mechanism error when the button is clicked.

@VerbisAnimae how exactly did you solve it?

Does this issue still persist? pyperclip doesn’t seem to work on Streamlit when the app is run even though it is added to the requirements.txt file.

I hope I could do it myself… but I don’t know enough to do it.

Anybody who has done it and wants to share it to everybody else?
Or maybe just a hint of how to start with code snippet and clipboard APIs
I really would like to use the phrase: “Copied to clipboard!” :smiley:

This issue still persists.
If anyone has any solution, please help.