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")Step 1. To get our sample project, download it as ZIP or clone it with the following command:
git clone https://github.com/flexmonster/pivot-r-shiny
Step 2. Invoke R and navigate to the pivot-r-shiny/ project folder:
setwd('<path_to_project>/pivot-r-shiny')Step 3. Run your application from the R program:
library(shiny) runApp()
The application will be automatically opened in your browser.
If you encounter any errors at this step, refer to the troubleshooting section.
Step 1. Create a new folder (e.g., shinyapp/) with index.html and app.r files inside.
Now you can start configuring the index.html.
Step 2. In the index.html file, include the flexmonster.js file:
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
Step 3. Create a <div> container for Flexmonster:
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivotContainer">The component will appear here</div>
Step 4. Add a script to embed the component:
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivotContainer">The component will appear here</div>
<script>
const pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true
});
</script>
Step 5. Configure a report:
<div id="pivotContainer">The component will appear here</div>
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<script type="text/javascript">
const pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
type: "json",
filename: "data/data.json"
}
}
});
</script>
Now the index.html is ready to be used, and we will proceed to configure the app.r file.
Step 6. In the app.r file, import Shiny into your application:
library(shiny)
Step 7. Create a simple server function:
server <- function(input, output) {
}Step 8. Define the user interface by calling the htmlTemplate() function with the path to the 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. Invoke R and navigate to the shinyapp/ project folder:
setwd('<path_to_project>/shinyapp')Step 11. Run your application from the R program:
library(shiny) runApp()
The application will be automatically opened in your browser.
If you encounter any errors at this step, refer to the troubleshooting section.
This section provides solutions to the errors you might encounter while completing this tutorial. If your error is not listed here, visit our troubleshooting page.
If you followed the tutorial and got this error, ensure the working directory of the R program is set to the project folder (e.g., ~/pivot-r-shiny/).
Alternatively, if you are using macOS or Ubuntu/Linux, you can open the terminal in the project folder and try one of the following:
RThen run the app using the commands described in step 11 of the integration process.
R -e "shiny::runApp()"or
Rscript app.r
Can't find your answer?
Visit the FAQ
Flexmonster Pivot Table & Charts is a JavaScript pivot table component for adding interactive reporting and data analysis to web applications. Users can summarize, filter, sort, and explore data in pivot tables and charts, drill into results, and export reports.
Flexmonster works in plain JavaScript and TypeScript projects. It also integrates with React, Next.js, Angular, Vue, Blazor, and other technologies. See all integration options.
Flexmonster supports JSON and CSV files, SQL databases, MongoDB, Elasticsearch, and Microsoft Analysis Services (SSAS). You can also connect other data sources through your own backend. See supported data sources.
Flexmonster offers licenses for internal corporate use, SaaS products, and OEM distribution. Pricing varies by license and plan. SaaS projects can also use the free SaaS Entry license during development. Learn more on the pricing page.
Yes. Flexmonster offers a 30-day free trial that lets you evaluate all its features. No credit card is required. The trial version has a watermark.
To get started with Flexmonster, follow our integration guide.