Shivang Singhal
Shivang Singhal

Reputation: 21

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

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) # reading table
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")  # plot bubble chart 
  )
))
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)})
    # plot bubble chart  
    output$plot1<- renderPlot(symbols(time(),prob(),circles=prob(),inches=.5,fg="white",bg="red")) 

  }
)

Any help is appreciated . Thanks in advance Shivang

Upvotes: 1

Views: 21741

Answers (1)

Mikael Jumppanen
Mikael Jumppanen

Reputation: 2486

You have defined ind as reactive function which means that you have to call it accordingly.

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

I think you have misunderstood idea about reactive functions. If you want to use reactivevalues you find help for that for example from here:

http://www.inside-r.org/packages/cran/shiny/docs/reactiveValues

Example code where I calculate values inside reactive function:

values <- reactiveValues()
getValues <- reactive({ values$ind <- which(visit[,1]%in%input$patient)}) )
output$plot1 <- renderPlot({
getValues()
symbols(values$time, values$prob... etc}) })

Upvotes: 2

Related Questions