I’m very new to the R/RStudio environment, and while working on a project, I couldn’t find anything on google/stack overflow about a Shiny issue I was having, so I decided to write about it myself!

My goal was to create a Shiny app that presents a dynamic data table with sliders and multipliers for the values within the table. I started with referencing the Shiny Gallery for code snippets that I could use to guide my R code.

This is an example of code from the based on the Shiny gallery:

output$table = DT::renderDataTable(DT::datatable({
    data = metrics
    if(input$device != 3) {
    data = data[data$device_type_id == input$device,]
    }
    if(input$days != 30) {
    data  = data[data$days_between <= input$days]
    }
}))

 

For some reason, this was not working out for me, and none of the examples discuss editing data table values dynamically. Unfortunately, I’m on a somewhat tight deadline, so I decide to replicate the methods I would use to look at this data on my own computer. If I’m using RStudio to play with data, dplyr is heavenly. Coming from a SQL/Excel analyst background, dplyr is intuitive and easy to use for filtering, examining, and manipulating data.

I plug in my dplyr version of the DataTable code, and it works!

output$table = DT::renderDataTable(DT::datatable({
    data = metrics
    if(input$device != 3) {
        data = filter(data, device_type_id == input$device)
    }
    if(input$days != 30) {
        data = filter(data, days_between <= input$days)
    presentation_data = data %>%
        group_by() %>%
        summarise(
            clicks = sum(clicks),
            sales = sum(sales)
        ) %>%
    arrange(desc(clicks))
})


Additionally, I was able to  modify values in the DataTable dynamically with dplyr:

if(input$percent != 1){
    data$clicks = portfolio_metrics$clicks * input$percent
    data$sales = portfolio_metrics$sales * input$percent
}

In the end, I was able to use dplyr functions in my server.R file to present a DataTable that could be filtered, manipulated, and understood easily by a non-technical user.

If anyone stumbles upon this while googling about how to present DataTables in Shiny apps, please don’t hesitate to leave a comment if this helps at all, and if I’m completely wrong, please let me know!

Advertisements

I watch their games with a level of agony and pleasure that only those who enjoy S&M understand. they are amazing. they are so amazing, illogical and so bad at the same time. their defense is near perfect, and their offense toes the line between clever plays and a hot mess.

Read More

I was recently hired by Sparefoot, Inc, as an SEO Intern. Sparefoot is a pretty small company, and has a lot of opportunity to move up or to the side, which is beneficial for me, because I would love to move both ways into an analyst position.

At work I was brought into “SQL SQOOL” (yes I named it that) by my supervisor. Fortunately I have spent a lot of time reading an SQL book over the summer, so the class is fairly simple for my purposes. What I do get out of it though is a different learning experience than I am used to for technical things, along with a firsthand look into the data structures of the company.

A few days after SQL SQOOL (all caps is the right way to read it), I helped my supervisor with a query he was working on, and visualized some of the data that we obtained from the query.

It felt good to see the effects of my reading and learned skills come into use into the workplace, and I am definitely going to do this more often.