Loading all libraries

library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggplot2)
library(shiny)
library(shinydashboard)
## 
## Attaching package: 'shinydashboard'
## The following object is masked from 'package:graphics':
## 
##     box

User Interface

ui.r

df <- read.csv("../data/labor-neg-clean")
numeric_cols <- sapply(df, is.numeric)
numeric_cols['dur'] = F
other_cols <- sapply(df, is.character)
other_cols['dur'] = T

ui <- fluidPage(
  title = "Arnab Banik",
  sidebarLayout(
    sidebarPanel(
      selectInput("field", "Select field", choices = colnames(df[numeric_cols])),
      selectInput("x", "X: ", choices = colnames(df[numeric_cols])),
      selectInput("y", "Y: ", choices = colnames(df[numeric_cols])),
      selectInput("class", "Color", choices = colnames(df[other_cols]))
    ),
    mainPanel(
      fluidRow(
        column(6, plotlyOutput("testPlot")),
        column(6, plotlyOutput("box"))
      ),
      fluidRow(
        column(6, plotlyOutput("myPlot")),
        column(6, plotlyOutput("lastPlot"))
      )
    )
  )
)

Server

server.r

dat <- read.csv("../data/labor-neg-clean")
server <- function(input, output){
  clr <- reactive({
    dat %>% select(input$field)
  })
  df <- reactive({
    dat %>% group_by(input$class) %>% summarise(freq = n())
  })
  output$testPlot <- renderPlotly({
    ggplotly(
      ggplot(clr(), aes(x = data.matrix(clr()))) + 
      geom_density(fill = "skyblue", color = "midnightblue", alpha = 0.6) +
      theme_bw() +
      labs(title = sprintf("%s density plot", colnames(clr())),
           x = colnames(clr()), y = "", fill = "", alpha = "")
    )
    })
  output$myPlot <- renderPlotly({
    ggplotly(
      ggplot(dat, aes(x = !!sym(input$x), y = !!sym(input$y), color = factor(!!sym(input$class)))) +
        geom_point() +
        theme_bw() +
        labs(title = sprintf("%s vs %s plot", input$x, input$y), color = input$class)
    )
  })
  output$box <- renderPlotly({
    ggplotly(
      ggplot(clr(), aes(y = data.matrix(clr()))) +
        geom_boxplot() +
        theme_bw() +
        labs(title = sprintf("%s boxplot", colnames(clr())), 
             x = colnames(clr()), y = "")
    )
  })
  output$lastPlot <- renderPlotly({
    ggplotly(
      ggplot(dat, aes(x = !!sym(input$class), fill = !!sym(input$class))) + geom_bar() +
        theme_bw()
    )
  })
}