Skip to content

Instantly share code, notes, and snippets.

@andre347 andre347/index.html
Created Oct 13, 2018

Embed
What would you like to do?
Tableau Extension: Step 5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Data-Refresh Tableau</title>
</head>
<body>
<h1>Hello Tableau!</h1>
<input type="number" name="refreshTime" id="refreshTime" placeholder="Time in Seconds">
<button id="btn">Start Refresh!</button>
<button id="btn-stop">Stop Refresh!</button>
<p id="info">Please specify seconds till refresh</p>
<script src="js/tableau-extensions-1.latest.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
// When the DOM has loaded, run the function load
document.addEventListener("DOMContentLoaded", load);
// Grab the input box, the buttons and paragraph
const input = document.querySelector("#refreshTime");
const btn = document.querySelector("#btn");
const btnStop = document.querySelector("#btn-stop");
const para = document.querySelector("#info");
// Create refresh variable
let refreshInterval = null;
function load() {
//initialise the tableau object
tableau.extensions.initializeAsync().then(() => {
console.log("Tableau object loaded");
// Eventlistener on the start button
btn.addEventListener("click", () => {
if (input.value !== "") {
para.innerHTML = `Refresh is running every ${input.value} seconds`;
refreshInterval = setInterval(() => {
initTableau();
}, input.value * 1000);
} else {
para.innerHTML = "Please specify seconds till refresh";
}
});
btnStop.addEventListener("click", () => {
if (input.value !== "") {
clearInterval(refreshInterval);
console.log("Stopped the refresh..");
para.innerHTML = "Refresh is not running";
}
});
});
}
function initTableau() {
// get the Tableau elements
const dashboard = tableau.extensions.dashboardContent.dashboard;
const sheets = dashboard.worksheets[0];
const datasource = sheets.getDataSourcesAsync();
// refresh said data source
console.log("Refreshing Datasource..");
datasource.then(source => source[0].refreshAsync());
}
@gittableauextensions

This comment has been minimized.

Copy link

commented Feb 23, 2019

Hi Andre,
Instead of using seconds, How can I use minutes instead? Thank you for your tutorial.

@gittableauextensions

This comment has been minimized.

Copy link

commented Feb 23, 2019

Thoms's link. He uses seconds. How can I displays in minutes instead? For example : 15 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.