<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Best way to make a scrollable DataFrame in a ipywidgets.Output? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/best-way-to-make-a-scrollable-dataframe-in-a-ipywidgets-output/m-p/4043#M878</link>
    <description>&lt;P&gt;I have a pretty complex Jupyter widgets UI in a databricks notebook that has a dataframe that&lt;/P&gt;&lt;P&gt;1. will be modified by some Jupyter &lt;B&gt;widget callbacks&lt;/B&gt;&lt;/P&gt;&lt;P&gt;2. needs to be displayed to the user and &lt;B&gt;updated as it is modified&lt;/B&gt;&lt;/P&gt;&lt;P&gt;3. is large and needs to support &lt;B&gt;vertical scrolling&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since callbacks cannot directly access cell output, I have to use a widget (either ipywidgets.Output or ipywidgets.HTML) to display the dataframe.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are the things I tried (finally succeeding with the 4th attempt/workaround):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;# Setup
import ipywidgets as widgets
import pandas as pd
pd.set_option("display.max_rows", 1000)
df = pd.DataFrame([[1, 2]] * 50)
&amp;nbsp;
# Attempt 1 - Use widgets.Output with databricks dataframe formatting
a1 = widgets.Output(layout={"scroll": "auto", "height": "300px"})
with a1:
    display(df)
display(a1)
##### RESULT ######
# &amp;lt;Databricks Output (not supported in output widgets)&amp;gt;
################
&amp;nbsp;
# Attempt 2 - Use widgets.Output with pandas dataframe formatting
from IPython.display import HTML
a2 = widgets.Output(layout={"scrollY": "auto", "height": "300px"})
with a2:
    display(HTML(df.to_html()))
display(a2)
##### RESULT ######
# Non-Databricks formatted pandas DataFrame but does not limit the height
# and there is no scrolling
################
&amp;nbsp;
# Attempt 3 - Use widgets.HTML with pandas dataframe formatting
from IPython.display import HTML
a3 = widgets.HTML(layout={"scroll": "auto", "height": "100px"})
a3.value = df.to_html()
display(a3)
##### RESULT ######
# Non-Databricks formatted pandas DataFrame and limit the height,
# but there is no scrolling, so the dataframe is truncated to a few rows.
################
&amp;nbsp;
# Attempt 4 - Use widgets.Output with pandas dataframe formatting and
#                       wrap it in a widgets.VBox
a4 = widgets.Output()
&amp;nbsp;
with a4:
    display(HTML(df.to_html()))
display(widgets.VBox(children=[a4], layout={"height": "300px", "scroll": "auto"}))
##### RESULT ######
# SUCCESS!!
# Non-Databricks formatted pandas DataFrame with scrolling enabled
################&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Clearly, using widgets.VBox wrapping widgets.Output with a workaround to use the pandas to_html instead of Databrick's to_html function is not ideal. Is there a better way to make a scrollable DataFrame in a Databricks notebook? Or is this the best workaround until "&amp;lt;Databricks Output (not supported in output widgets)&amp;gt;" is fixed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 24 May 2023 01:28:30 GMT</pubDate>
    <dc:creator>yhyhy3</dc:creator>
    <dc:date>2023-05-24T01:28:30Z</dc:date>
    <item>
      <title>Best way to make a scrollable DataFrame in a ipywidgets.Output?</title>
      <link>https://community.databricks.com/t5/data-engineering/best-way-to-make-a-scrollable-dataframe-in-a-ipywidgets-output/m-p/4043#M878</link>
      <description>&lt;P&gt;I have a pretty complex Jupyter widgets UI in a databricks notebook that has a dataframe that&lt;/P&gt;&lt;P&gt;1. will be modified by some Jupyter &lt;B&gt;widget callbacks&lt;/B&gt;&lt;/P&gt;&lt;P&gt;2. needs to be displayed to the user and &lt;B&gt;updated as it is modified&lt;/B&gt;&lt;/P&gt;&lt;P&gt;3. is large and needs to support &lt;B&gt;vertical scrolling&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since callbacks cannot directly access cell output, I have to use a widget (either ipywidgets.Output or ipywidgets.HTML) to display the dataframe.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are the things I tried (finally succeeding with the 4th attempt/workaround):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;# Setup
import ipywidgets as widgets
import pandas as pd
pd.set_option("display.max_rows", 1000)
df = pd.DataFrame([[1, 2]] * 50)
&amp;nbsp;
# Attempt 1 - Use widgets.Output with databricks dataframe formatting
a1 = widgets.Output(layout={"scroll": "auto", "height": "300px"})
with a1:
    display(df)
display(a1)
##### RESULT ######
# &amp;lt;Databricks Output (not supported in output widgets)&amp;gt;
################
&amp;nbsp;
# Attempt 2 - Use widgets.Output with pandas dataframe formatting
from IPython.display import HTML
a2 = widgets.Output(layout={"scrollY": "auto", "height": "300px"})
with a2:
    display(HTML(df.to_html()))
display(a2)
##### RESULT ######
# Non-Databricks formatted pandas DataFrame but does not limit the height
# and there is no scrolling
################
&amp;nbsp;
# Attempt 3 - Use widgets.HTML with pandas dataframe formatting
from IPython.display import HTML
a3 = widgets.HTML(layout={"scroll": "auto", "height": "100px"})
a3.value = df.to_html()
display(a3)
##### RESULT ######
# Non-Databricks formatted pandas DataFrame and limit the height,
# but there is no scrolling, so the dataframe is truncated to a few rows.
################
&amp;nbsp;
# Attempt 4 - Use widgets.Output with pandas dataframe formatting and
#                       wrap it in a widgets.VBox
a4 = widgets.Output()
&amp;nbsp;
with a4:
    display(HTML(df.to_html()))
display(widgets.VBox(children=[a4], layout={"height": "300px", "scroll": "auto"}))
##### RESULT ######
# SUCCESS!!
# Non-Databricks formatted pandas DataFrame with scrolling enabled
################&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Clearly, using widgets.VBox wrapping widgets.Output with a workaround to use the pandas to_html instead of Databrick's to_html function is not ideal. Is there a better way to make a scrollable DataFrame in a Databricks notebook? Or is this the best workaround until "&amp;lt;Databricks Output (not supported in output widgets)&amp;gt;" is fixed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 01:28:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/best-way-to-make-a-scrollable-dataframe-in-a-ipywidgets-output/m-p/4043#M878</guid>
      <dc:creator>yhyhy3</dc:creator>
      <dc:date>2023-05-24T01:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to make a scrollable DataFrame in a ipywidgets.Output?</title>
      <link>https://community.databricks.com/t5/data-engineering/best-way-to-make-a-scrollable-dataframe-in-a-ipywidgets-output/m-p/4045#M880</link>
      <description>&lt;P&gt;Hi @Yushi Homma​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for posting your question in our community! We are happy to assist you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 00:40:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/best-way-to-make-a-scrollable-dataframe-in-a-ipywidgets-output/m-p/4045#M880</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-29T00:40:01Z</dc:date>
    </item>
  </channel>
</rss>

