This tutorial will help you integrate Flexmonster into an R Shiny application. It is based on the how to build a Shiny app guide.
install.packages("shiny")
This guide contains the following sections:
Step 1. Download a .zip
archive with the sample or clone it from GitHub with the following commands:
git clone https://github.com/flexmonster/pivot-r-shiny
cd pivot-r-shiny
Step 2. Run your application from the R console:
library(shiny) runApp('~/pivot-r-shiny')
The application will be automatically opened in your browser.
It can be shut down manually with Ctrl + C
.
If any errors appear on this step, refer to the troubleshooting section.
To integrate Flexmonster into an R Shiny application, follow these steps:
Step 1. If you don’t have an R Shiny app yet, create a new empty folder (e.g., shinyapp/
) with an empty app.r
file inside.
Step 2. In the app.r
file, import Shiny into your application:
library(shiny)
Step 3. In the app.r
file, define a simple server function:
server <- function(input, output) { }
Step 4. In an .html
file (e.g., index.html
), create a <div>
container for the component:
<div id="pivotContainer">The component will appear here</div>
Step 5. Include flexmonster.js
in your HTML page:
<div id="pivotContainer">The component will appear here</div> <script src="https://cdn.flexmonster.com/flexmonster.js"></script>
Step 6. Add a simple script to embed the component:
<div id="pivotContainer">The component will appear here</div>
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<script>
var pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true
});
</script>
Step 7. Configure a simple report:
<div id="pivotContainer">The component will appear here</div> <script src="https://cdn.flexmonster.com/flexmonster.js"></script> <script type="text/javascript"> var pivot = new Flexmonster({ container: "pivotContainer", componentFolder: "https://cdn.flexmonster.com/", toolbar: true, report: { dataSource: { type: "json", filename: "data/data.json" } } }); </script>
Step 8. In the app.r
file, define the user interface by calling the htmlTemplate
function with the HTML file path (e.g., index.html
) as a parameter.
ui <- htmlTemplate("index.html")
Step 9. Add the shinyApp
function that uses the ui
object and the server
function to build a Shiny app object:
shinyApp(ui, server)
Step 10. Run your application from the R console:
library(shiny)
runApp('~/shinyapp')
The application will be automatically opened in your browser.
It can be shut down manually with Ctrl + C
.
If any errors appear on this step, refer to the troubleshooting section.
While completing this tutorial, users may face problems with running the app, especially macOS or Linux users. This section provides solutions to the errors you may encounter. If your error is not listed here, contact our technical support.
If you followed the tutorial accurately and got this error, try the following:
pivot-r-shiny/
), the runApp
function should be called without parameters:library(shiny)
runApp()
The following instructions only apply to UNIX-like systems (macOS, Linux, etc.):
RThen run the app with commands from the guide:
library(shiny)
runApp('~/pivot-r-shiny')
pivot-r-shiny/
) and run the following command:R -e "shiny::runApp()"
Rscript app.R
You may be interested in the following articles: