Error in xj[i] : invalid subscript type 'closure'

1,965 views
Skip to first unread message

Shivang Singhal

unread,
Nov 18, 2014, 12:58:37 AM11/18/14
to shiny-...@googlegroups.com
I am getting this error when trying to run shiny application.

Error in xj[i] : invalid subscript type 'closure'

following are ui.R and server.R files.

ui.R
=========
visit = read.csv("lookuptable.csv",head=T)
visit = visit[1:39,1:22]
shinyUI(pageWithSidebar(
  headerPanel('Disease Risk Prediction'),
  sidebarPanel(
    selectInput("patient",
                label = "Patient",
                choices = as.character(visit[,1]),
                selected = as.character(visit[1,1]),multiple = FALSE)
   
    ),
  mainPanel(
    plotOutput("plot1")
  )
))
server.R
==========
library(shiny)
shinyServer(
  function(input, output) {
    visit <- read.csv("lookuptable.csv",head=T)
   
    visit <- visit[1:39,1:22]
   
    ind   <- reactive({which(visit[,1]%in%input$patient)})
     prob <- reactive({as.numeric(visit[ind,c("prob1","prob2","prob3","prob4","prob5")])})
     time <- reactive({as.numeric(visit[ind,c("time1","time2","time3","time4","time5")])})
     icd <- reactive({visit[ind,c("icd1","icd2","icd3","icd4","icd5")]})
     icd <- reactive({apply(icd,2,as.character)})
      output$plot1 <-renderPlot(symbols(time(),prob(),circles=prob(),inches=.5,fg="white",bg="red"))
 
  }
)

Any help is appreciated .
Thanks in advance
Shivang

Joe Cheng

unread,
Nov 18, 2014, 12:59:19 PM11/18/14
to Shivang Singhal, shiny-...@googlegroups.com
To use the value for a reactive expression (e.g. "ind"), you use ind(). So the prob reactive should be defined as (note the bold):

     prob <- reactive({as.numeric(visit[ind(),c("prob1","prob2","prob3","prob4","prob5")])})

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/7bdffa66-bc68-47a1-8524-c7c9ec4fd18f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shivang Singhal

unread,
Nov 19, 2014, 12:03:14 AM11/19/14
to shiny-...@googlegroups.com, shivang...@enlightiks.com
Thanks lot :-)
working now :-) :-)
Reply all
Reply to author
Forward
0 new messages