Skip to content

Instantly share code, notes, and snippets.

@andre347
Created October 13, 2018 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andre347/6b96278bf02f45a56e681ae4c75e8291 to your computer and use it in GitHub Desktop.
Save andre347/6b96278bf02f45a56e681ae4c75e8291 to your computer and use it in GitHub Desktop.
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
Copy link

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

@gittableauextensions
Copy link

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