Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue May 25, 2024 · 2 comments

Comments

@jj-github-jj
Copy link

jj-github-jj commented May 25, 2024

# 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
Copy link
Author

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
Copy link
Collaborator

@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 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants