Skip to content
This repository has been archived by the owner on May 29, 2018. It is now read-only.

How To hide table after showing it #102

Open
AhmedEmadAhmed opened this issue Jul 12, 2016 · 3 comments
Open

How To hide table after showing it #102

AhmedEmadAhmed opened this issue Jul 12, 2016 · 3 comments

Comments

@AhmedEmadAhmed
Copy link

How to hide shown table after viewing it from export

@dplatten
Copy link

I wanted to do this too, and have modified the source code to allow it. My modifications assume that the user has jQuery available to them. You need to modify the "View the data table below the chart" section of the code as shown below. With these modifications when you click on "Toggle data table" a second time the table is hidden again:

    /**
     * View the data in a table below the chart
     */
    Highcharts.Chart.prototype.viewData = function () {
        if (!this.insertedTable) {
            var div = document.createElement('div');
            div.className = 'highcharts-data-table';
            // Insert after the chart container
            this.renderTo.parentNode.insertBefore(div, this.renderTo.nextSibling);
            div.innerHTML = this.getTable();
            this.insertedTable = true;
            div.id = this.container.id + '-data-table';
        }
        else {
            $('#' + this.container.id + '-data-table').toggle();
        }
    };

I've also renamed the "View data table", towards the top of the code, to "Toggle data table":

    Highcharts.setOptions({
        lang: {
            downloadCSV: 'Download CSV',
            downloadXLS: 'Download XLS',
            viewData: 'Toggle data table'
        }
    });

I hope this helps you.

David

@dplatten
Copy link

My first attempt (above) used the chart's DIV container name as part of the data-table DIV name. This may fail. Also, there may be more than one chart in the DIV container. The following is more robust:

    /**
     * View the data in a table below the chart
     */
    Highcharts.Chart.prototype.viewData = function () {
        if (!this.insertedTable) {
            var div = document.createElement('div');
            div.className = 'highcharts-data-table';
            // Insert after the chart container
            this.renderTo.parentNode.insertBefore(div, this.renderTo.nextSibling);
            div.innerHTML = this.getTable();
            this.insertedTable = true;
            var date_str = new Date().getTime().toString();
            var rand_str = Math.floor(Math.random() * (1000000)).toString();
            this.insertedTableID = 'div_' + date_str + rand_str
            div.id = this.insertedTableID;
        }
        else {
            $('#' + this.insertedTableID).toggle();
        }
    };

@cinkie
Copy link

cinkie commented Sep 29, 2017

I created a .js file with code provided by @dplatten , put the file in www/ folder, and include this in ui.r (tags$head(tags$script(src = 'this_script.js'))). It works perfectly! Thanks for the advice. 👍

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

No branches or pull requests

3 participants