top of page

Make Your Shiny Apps Excel

Aug 11, 2017
2 min read

Make your Shiny Apps Excel

"Can I view that in Excel?"

The capabilities of R programming are expanding. Fast. From publication-quality graphics with ggplot2 to the capability to handle large scale computing with Apache Spark, the analytics community embraces R as a core environment. At CANA Advisors, we use the latest developments in order to deliver the fastest, most adaptable solutions. For clients, results need to be in a form that is easy to process by any member of their team-- with little to no learning curve.

As analytics professionals, how can we ensure the best of both worlds? That is, state of the art solutions that produce results in the familiar form clients seek.

In this post, I'll go over one such method: using R programming to export the results of a Shiny analysis to Microsoft Excel. For those not familiar with Shiny, it is a package to create interactive, aesthetically pleasing web apps with all the statistical capability of the R programming language. This brief tutorial will utilize the Shiny and XLConnect packages in R.

The Method

In this example, we'll be working with the iris data set [1], which contains information about the dimensions of different instances of various iris flower species. For the purpose of this tutorial, we'll assume we already have a functioning Shiny app and the data structures we are interested in saving. In this case, the data we'd like to store is reactive in nature. This means, it will change with user inputs. You can recognize calls to reactive expressions in the code below by their distinctive form expression(). To export a worksheet:

1. Lay the groundwork: Create the download button, workbook, and worksheets. 2. Assign the data frames to the worksheets. 3. Save and download.

The Result

The above process will take us from a shiny app like this:

Shiny App process example

To an excel file like this:

Excel example from Shiny

The Implementation

# Load the shiny and XLConnect packages library(shiny); library(XLConnect) # Create and label the download button that will appear in the shiny app renderUI({ downloadButton("downloadExcel", "Download") }) output$downloadFile <- downloadHandler(filename = "Iris_data.xlsx", content = function(file) # Name the file fname <- paste(file, "xlsx", sep = ".") # Create and assign names to the blank workbook and worksheets wb <- loadWorkbook(fname, create = TRUE) createSheet(wb, name = "Sepal Data") createSheet(wb, name = "Petal Data") # Write the reactive datasets to the appropriate worksheets writeWorksheet(wb, sepal(), sheet = "Sepal Data") writeWorksheet(wb, petal(), sheet = "Petal Data") # Save and prepare for download saveWorkbook(wb) file.rename(fname, file) })

To learn more about any of the features discussed above, use the ?topic feature in R. A more comprehensive overview of shiny is provided by RStudio here.

Lucia Darrow is an valued Operation Research Analyst at CANA Advisors to read more R articles by her and other members of the CANA Team visit the CANA Blog.

[1] In R, type ?iris to learn more than you would ever want to know about it.

 
 
 

9 Comments


ziti
a day ago

Ventilation systems help move fresh air through buildings while removing stale indoor air. Proper ventilation can be particularly important in offices, commercial facilities, and tightly enclosed residential spaces. Professional HVAC technicians can inspect ventilation equipment, airflow pathways, fans, and related controls to identify possible issues. When ventilation is inadequate, professionals can recommend suitable improvements based on building requirements. Maintaining effective ventilation supports balanced airflow and contributes to a more comfortable indoor environment when https://citylineairconditioning.com/ combined with properly functioning heating and cooling equipment.

Like

jorapag
Sep 14

Access control is one of the most important responsibilities provided by many security professionals. A security guard company can help businesses establish organized procedures for employees, contractors, visitors, and deliveries. Guards may check identification, maintain visitor records, and communicate access requirements clearly. Effective access management helps property managers understand who is entering or leaving a facility while reducing confusion at entrances. Professional guards can also provide assistance to authorized visitors while maintaining established security 24/7 security services Houston standards.

Like

jorapag
Sep 11

Roof maintenance is one of the most effective ways to protect a property from avoidable roofing problems. A professional can provide inspections and maintenance services designed to identify concerns before they become serious. Cleaning debris, checking flashing, examining shingles, and reviewing drainage areas are common maintenance tasks. Regular attention can help preserve roofing materials and reduce unexpected repair costs. A well-maintained roof also Roofing Company contributes to the building’s overall structural protection and long-term property value.

Like

neki
Sep 10

Another advantage of residential retractable roofs is improved shade management. Fixed covers provide permanent shade, which may not always be desirable. A retractable system allows homeowners to decide when shade is needed and when sunlight should be welcomed. This makes it easier to create a comfortable environment during different times of the day. Adjustable shade can be especially valuable during https://cabriostructures.com/ warmer months, when direct sunlight may make outdoor seating areas uncomfortable for extended periods.

Like

koxu
Aug 18

Adoption education can also help families understand the importance of lifelong relationships. An adopted child may have questions about birth relatives, heritage, and personal history at different stages of development. Parents who remain open and https://www.adopthelp.com/ supportive can create an environment where those conversations feel safe. Depending on the circumstances and professional guidance, maintaining appropriate connections may be beneficial. Respecting a child's emotional needs helps families build trust and demonstrates that adoption can be discussed honestly and compassionately.

Like
bottom of page