man-group / dtale

Visualizer for pandas data structures
http://alphatechadmin.pythonanywhere.com
GNU Lesser General Public License v2.1
4.62k stars 390 forks source link

unable to set title of the tab using dtale.show() . please support the main_title as an argument for the dtale.show #864

Closed jj-github-jj closed 1 week ago

jj-github-jj commented 1 month ago
# unable to set the title of the web page tab being displayed by 
# after looking at dtale views.py came up with this workaround but this should really not be required and should be builtin
# as an optional argument for dtale.show method

import dtale
from dtale.global_state import get_app_settings, set_app_settings
import pandas as pd

def show_with_custom_title(df, title, name=None):
    # Set the main_title in the application settings
    settings = get_app_settings()
    settings['main_title'] = title
    set_app_settings(settings)

    # Display the DataFrame in D-Tale
    return dtale.show(df, name=name)

# Example usage
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
d = show_with_custom_title(df, "My Custom Title", name="custom_dataset_name")
jj-github-jj commented 1 month ago

I also changed views.py as follows

def _view_main(data_id, iframe=False):
    """
    Helper function rendering main HTML which will also build title and store whether we are viewing from an <iframe>

    :param data_id: integer string identifier for a D-Tale process's data
    :type data_id: str
    :param iframe: boolean flag indicating whether this is being viewed from an <iframe> (usually means ipython)
    :type iframe: bool, optional
    :return: HTML
    """
    title = "D-Tale"
    main_title = global_state.get_app_settings().get("main_title") # TODO
    print (f'main title: {main_title}')
    title = main_title or "D-Tale2" # TODO
    name = global_state.get_name(data_id)
    if name:
        title = "{} ({})".format(title, name)
    return base_render_template("dtale/main.html", data_id, title=title, iframe=iframe)
aschonfeld commented 1 week ago

@jj-github-jj you can now set these properties by doing the following:

d = dtale.show(df, main_title="test title", main_title_font="Arial")

If you don't set the main_title_font it will just take the default font you see now for the title.

I have added this functionality to the v3.13.0 release on pypi (will be on conda-forge shortly). Let me know if you have any issues. Also, whenever you get a sec would you mind tossing your ⭐ on the dtale repo? Thanks 🙏