【问题标题】:Error in xj[i] : invalid subscript type 'closure'xj[i] 中的错误:无效的下标类型“闭包”
【发布时间】:2015-01-15 06:01:28
【问题描述】:

我在尝试运行闪亮的应用程序时收到此错误。

xj[i] 中的错误:无效的下标类型“闭包”

以下是 ui.R 和 server.R 文件。

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")) 

  }
)

感谢任何帮助。 提前致谢 石旺

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您已将ind 定义为反应函数,这意味着您必须相应地调用它。

    修正示例代码行:prob&lt;- reactive({as.numeric(visit[ind(),c("prob1","prob2","prob3","prob4","prob5")])})

    我认为您对反应函数有误解。如果你想使用反应值,你可以从这里找到帮助:

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

    我在反应函数中计算值的示例代码:

    值 getValues 输出$plot1 获取值()
    符号(值$时间,值$概率...等})})

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 2015-09-26
      相关资源
      最近更新 更多