At RStudio, we strive to help you combine the power of code-first data science with the other tools in your toolkitOpens a new window. Many organizations rely on TableauOpens a new window for creating data dashboards, but there may be moments where you wish you could take advantage of R’s powerful reporting and visualization capabilities as well.
With the experimental shinytableauOpens a new window package, you can use the power of R and Shiny to customize objects that you embed in your Tableau dashboards. This package opens up the possibility to include interactive features beyond Tableau’s native capabilities, allowing you to be more flexible in meeting your organization’s data needs.
Embed Custom R Objects in a Tableau Dashboard
Is that a ggplot2 visualization in Tableau? With shinytableau, you can sit Tableau’s visualizations side-by-side with anything you can create in a Shiny application, including custom charts created with ggplot2. Since the Shiny app is embedded in Tableau, users of the dashboard won’t need to learn R or even realize they’re using a different tool.
Configure Shiny Apps to “Talk” to Tableau
Say you want to interactively use your extension with Tableau, such as pulling data from a worksheet to populate your chart. You can use Shiny to create a friendly user interface for specifying settings for your extension. With the right configuration, your Shiny app and Tableau can interact so that you can tell a cohesive story in your Tableau dashboard.
Deploy and Host Shiny Apps for Production
You can deploy shinytableau extensions like any other Shiny app, which allows you to use them in production. RStudio offers RStudio Connect and shinyapps.io as options to publish and host your Shiny apps. Read more on the Deployment and HostingOpens a new window page of the shinytableau documents.
How to Use shinytableau
The authors of the shinytableau package, Joe Cheng, Richard Iannone, and Javier Luraschi, wrote a great tutorial on getting started with shinytableauOpens a new window. We highly recommend going through the tutorial to get a full understanding of the components of shinytableau, how they work together, and why each step is needed.
Here, we’ll break down the main steps of creating the authors’
ggviolin extension and how to embed it in Tableau’s Superstore sample workbookOpens a new window. Note that the violin plot in the videos has an applied palette and theme while the violin plot in the tutorial does not. Like any ggplot2 visualization, you can customize the plot to look how you would like!
Let’s begin in your RStudio console.
1. Start a new RStudio projectOpens a new window
2. Install packages
Install your required packages. In addition to the packages you need for your Shiny app, you will also need remotes and shinytableau.
3. Edit the
Once shinytableau is installed, run the code below to open the
manifest.yml file. Edit the metadata to fit your extension. See an example in the shinytableau Github repositoryOpens a new window.
4. Create the shinytableau extension Shiny app
The next step is to create the extension. In addition to creating a Shiny app, you also need to configure the app so that it can interact with Tableau. This is the most technical part of the whole workflow and the tutorial details how to do this thoughtfully and in detail.
You can use the
ggviolin app code in the shinytableau Github repositoryOpens a new window as an example. Save this file as
app.R in your project.
5. Run the app and download the
app.R file and a dialogue box will appear. Click “Download” to download a
.trex file, which is what Tableau will use to create the extension.
Now, let’s move to Tableau. Be sure to leave your Shiny app running in RStudio! Otherwise, the connection will be lost and Tableau will not be able to open the extension.
6. Open the Superstore sample workbook in Tableau
The Superstore workbook should be available under Sample Workbooks:
If you want to create the same violin plots as you see in the images in this post, go to the “Performance” workbook. Under “Measure Names”, you can find “Profit Ratio”. Drag “Profit Ratio” under “Marks”.
7. Create the dashboard and load .trex file
Go to “Dashboard” then “New Dashboard”. In the new dashboard, drag the “Performance” workbook to where it says “Drop Sheets Here”, and then drag the “Extension” object to the dashboard. The “Add an Extension” box will automatically open.
Click “Access Local Extensions”, which will open a window. Navigate to and open your .trex file. Tableau will ask if you agree to open the extension. Click “OK” and your extension will appear in the dashboard.
8. Configure the extension
The Shiny app is in Tableau, but it doesn’t know what data to use. The next step is configuring the extension so that it uses the “Performance” worksheet data to render the violin plot.
Click the triangle button of the extension object, then go to “Configure”. This will open a dialogue box created in the Shiny app.
Fill out the form. Give it a title, choose the “Performance” worksheet, and select “Category” as the dimension and “AGG(Profit Ratio)” as the measure.
When you click “OK”, you will see the violin plot populate in the extension object. Congratulations! With the shinytableau package, you created a Tableau dashboard extension using R and Shiny.
Using the power of R and Shiny, you can combine the powers of your available tools to create insightful dashboards. shinytableau is still experimental and we would love your feedbackOpens a new window on what you hope to see from the package.
We recommend reviewing the tutorialOpens a new window for shinytableau to learn more about how to customize it to your needs.
Looking for other ways of leveraging the power of R and Python with Tableau? Last week, we announced support for Tableau Analytics Extensions on RStudio ConnectOpens a new window, which allows you to create calculated fields in workbooks that can execute R and Python scripts outside of the Tableau environment.
Learn more about leveraging business intelligence tools like Tableau alongside open source data science at our RStudio Community Enterprise Meetup on Leveraging R & Python in Tableau with RStudio ConnectOpens a new window on Friday, October 29, 2021.