0

I am looking to build one interactive data visualisation. My dataset contains 1244 obs and 9 variables sharing a screenshot of data below: Screenshot of sample Dataset

Flow of data visualisation:

  1. Select the company name from an input box and it will give an output table (subset of that company from main dataset)

  2. Select DIR of the above compary from an input box

  3. After deleting the DIR, it will give an output of the company name (after checking the main dataset), if it is present.

Code which I have written is provided below, but it is not working. I will appreciate valuable input. Thanks in advance.

UI

navbarPage(
title = "SHELL COMPANY",
tabPanel("COMPANY INFO",
fluidRow(
  column(4, selectInput("name","COMPANY NAME:", c("ALL", unique(as.character(cmp$`STD COMPANY NAME`))))),
  column(4, DT::dataTableOutput("table")
  ))),
tabPanel("DIR INFO",
  fluidRow(
    column(4, selectInput("dir","DIRECTOR NAME:", sort(unique(as.character(cmp$`DIR NAME`)))))),
  column(4, DT::dataTableOutput("table2"))
))

SERVER

function(input,output)
{
data <- cmp
rv <- reactiveValues() 
observe({
rv$table <-  cmp
if(input$name!="ALL"){
  rv$table <- data[data$`STD COMPANY NAME`==input$name,]
} 
})
output$table <- DT::renderDataTable(DT::datatable(
{
  rv$table
}))
output$table2 <- DT::renderDataTable(DT::datatable(
{
  data2 <- rv$table
  data2 <- subset(rv$table, data$'DIR NAME'==input$dir, select=c(`STD COMPANY NAME`, `DIR NAME`))
  data2
}))}
Community
  • 1
  • 1
PritamJ
  • 337
  • 4
  • 10
  • 1
    A small dataset using dput(), seee https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example would be helpful. – Florian Jul 19 '17 at 08:51
  • While editing, I moved one curly brace in output$table2. Check if this changed something. And please, state what error you are facing. – K. Rohde Jul 19 '17 at 09:28
  • why do you have different quotes in `subset(data, data$'DIR NAME'==input$dir, select = ....` ? – vladli Jul 19 '17 at 10:16
  • @ClaudH: Thank you i rectify that . Error i am receiving is Error in table$`STD COMPANY NAME` : object of type 'closure' is not subsettable – PritamJ Jul 19 '17 at 10:28
  • @K.Rohde: Error in table$`STD COMPANY NAME` : object of type 'closure' is not subsettable. – PritamJ Jul 19 '17 at 10:30
  • @K.Rohde: table is the output of the first input . i was wondering ,when i call table$`STD COMPANY NAME` for my second input.. was it the right approach or is any default function for it. May be thats why it showing error. – PritamJ Jul 19 '17 at 11:00
  • @PritamJ You are calling some variable `table` in your ui.R, which is not defined in the scope of that file. (I guess table is some built-in reference there and no , which causes the closure error.) What is that `table` supposed to be? – K. Rohde Jul 19 '17 at 14:00

1 Answers1

0

If the snippet that you provided is all you've got in the app concerning the error, it seems that you try to assign output$table to another variable inside output$table2 at data2 <- table. You can't assign output$... like that. Try creating separate table (?reactiveValues() might come in handy), and use it in both outputs, so the logic looks like this:

rv <- reactiveValues() 
observe({
    rv$table <-  cmp
    if(input$name!="ALL"){
      rv$table <- data[data$`STD COMPANY NAME`==input$name,]
    } 
})

Then use it in both output$table and output$table2

vladli
  • 1,454
  • 2
  • 16
  • 40
  • reactiveValues() did work. One final problem i am facing is i want to highlight only those DIR NAME which are there in tableoutput(table). I am using this command now column(4, selectInput("dir","DIRECTOR NAME:", sort(unique(as.character(cmp$`DIR NAME`)))))) , which i know is wrong. What should i call instead of cmp$`DIR NAME`?? – PritamJ Jul 20 '17 at 06:54