2014-11-18 1 views
1
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)}) 

출력 $ plot1 < -renderPlot (심볼 (시간(), PROB(), 원 = PROB(), 인치 = 0.5, FG = " 어떤 도움에 감사드립니다오류 [I] : 잘못된 첨자 형 '폐쇄'

} 
) 

흰색 ", BG ="빨간색 ")) # 플롯 버블 차트. 당신은 당신이 적절하게 호출 할 필요가 있다는 것을 의미 ind 반응성 기능을 정의한 사전 Shivang

+0

아아,이 포스트는 오류 텍스트의 상단 구글 결과이지만,이다 형식이 잘못되어 "주로 코드"오류로 인해 편집 할 수 없습니다. – Dragomok

답변

2

에 감사합니다.

고정 예제 코드 라인 : prob<- reactive({as.numeric(visit[ind(),c("prob1","prob2","prob3","prob4","prob5")])})

난 당신이 반응 기능에 대한 아이디어를 오해 생각합니다. 당신이 reactivevalues를 사용하려면 여기에서 예를 들어 그에 대한 도움말을 찾을 : 나는 반응 함수 내에서 값을 계산

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

예제 코드 :

값 < - reactiveValues ​​()
에 getValues을 < - 반응성 ({ 값 $ ind < - (% [$ 1] % input $ patient)}))
출력 $ 플롯- renderPlot ({
에 getValues ​​()
문자 (값 $ 시간, 값 $의 확률값 ... 등})})