In Dynamics 365 Unified Interface, you can show and hide a dashboard button based on the currently open dashboard by creating an enable rule on your button in the ApplicationRibbon entity.

To achieve this, add the following JavaScript code to a CustomRule on your enable rule with the Ribbon Workbench.

function showDashboardButton() {
    var dashboardId = "99c027f2-c4d9-4f5d-8107-089b24cf25e4"; //replace this value with the ID of your dashboard
    var url = window.parent.location.href;
    console.log(url);

    if (url.includes(dashboardId)){
        console.log("showDashboardButton: True");
        return true;
    } else {
        console.log("showDashboardButton: False");
        return false
    }
};