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&LT; -renderPlot(符号(时间(),概率(),圆=概率(),英寸= 0.5,FG =&#34;白色&#34;,BG =&#34;红色&# 34;))#plot bubble chart
}
)
感谢任何帮助。 提前致谢 Shivang
答案 0 :(得分:2)
您已将ind
定义为被动功能,这意味着您必须相应地调用它。
修复了示例代码行:prob<- reactive({as.numeric(visit[ind(),c("prob1","prob2","prob3","prob4","prob5")])})
我认为你误解了反应函数的想法。如果你想使用反应值,你可以找到帮助,例如从这里:
http://www.inside-r.org/packages/cran/shiny/docs/reactiveValues
我在反应函数内计算值的示例代码:
值&lt; - reactiveValues()
getValues&lt; - reactive({ 值$ ind&lt; - 其中(访问[,1]%in%input $ patient)}) )
输出$ plot1&lt; - renderPlot({
的GetValues()
符号(值$ time,values $ prob ... etc})})