cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Word wrap in dashboards

DavidKxx
Contributor

When I'm displaying a Table-style visualization in a notebook dashboard, is there a setting I can apply to a text column so that it automatically word-wraps text longer than the display width of the column?

For example, in the following dashboard display, I have clicked the pointer symbol in row 2 to make the entire string visible.  I want the notebook to do this automatically for all cells, or for all cells in a specific column.

solution3.png

1 REPLY 1

filipniziol
Contributor III

Hi @DavidKxx ,

That is quite similar question to one about displaying array as bullet list. 
Since you were successful in implementing displayHTML, what do you think about doing similar in this case?

 

# Sample DataFrame with long text
data = [
    (1, 'This is a short text.'),
    (2, 'This is a much longer text that would normally be truncated in a standard table visualization, but we want it to wrap automatically within the cell without needing to expand the cell manually.')
]

df = spark.createDataFrame(data, ['id', 'text'])

# Collect data to the driver
rows = df.collect()

# Start building the HTML string
table_html = '''
<style>
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    border: 1px solid black;
    text-align: left;
    padding: 8px;
    word-wrap: break-word;
    word-break: break-word;
    max-width: 200px; /* Adjust the max-width as needed */
}
</style>
<table>
    <tr>
        <th>id</th>
        <th>text</th>
    </tr>
'''

# Add table rows
for row in rows:
    table_html += '<tr>'
    table_html += f'<td>{row["id"]}</td>'
    table_html += f'<td>{row["text"]}</td>'
    table_html += '</tr>'

table_html += '</table>'

displayHTML(table_html)

 

filipniziol_0-1727420058191.png

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group