Option to read data from clipboard

Dear Team,

I would like to understand if we have a functionality to copy data from clipboard similar to pandas read from clipboard option.

My intended use case is as follows -

  1. User can copy a part of excel sheet (just few rows and columns)
  2. Select a button to directly read from clipboard
  3. Paste it in a text area
  4. Used the copied data (with formatting retained) to read it as pandas dataframe (maybe by using pd.read_clipboard)

Let me know if there is a way to achieve this using streamlit or any possible workaround.


1 Like

I dont think capturing navigator data is supported in streamlit yet.

You can try building a custom component for it perhaps.
The logic would be on a event, capture navigator.clipboard.readText(), wrap it with StringIO and pass it to pd.read_csv with separator of your choice. ( by default pd.read_seperator is pd.read_csv with \s+ I guess )

https://alligator.io/js/async-clipboard-api/ <- some js side reference.

PS. I am working on a streamlit component that exposes the navigator apis eg. geo, battery, clipboard etc. , will have something available (unstable) around the weekend :slight_smile: you would be able to do,

import pandas as pd
from io import StringIO

clip_data = stnav.clipboard.get_text()
pd.read_csv(StringIO(clip_data), sep="\\s+")

with that probably. and Most welcome to this awesome community !

1 Like