0
votes

In the below toy example I have a data set datapred. The data set are output to an interactive table using rhandsontable. Then I covert it in a new data.frame with hot_to_r. My issue is that when I wnat to use it in my function prediction(), it send me an error message and the application crash. I don't understand why.

I'm french so I converted in english the message : Error in as.name: the 'pairlist' object can not be automatically converted to a 'symbol' type.

library(shiny)
library(frailtypack)
library(rhandsontable)
data("readmission", package = "frailtypack")

ui <- fluidPage(
  titlePanel("prediction"),

  mainPanel(
  fluidRow(rHandsontableOutput("hot")),
  br(),
  plotOutput("pred")
  )
)

server <- function(input, output) {

newdata <- subset(readmission,select = c("time","event","id","dukes"))

datapred <- newdata[1,]

data <- reactive({
  DF = hot_to_r(input$hot)
  DF
})

model <- frailtyPenal(Surv(time,event)~cluster(id)+dukes,n.knots=10,
                    kappa=10000,data=readmission)

predict <- reactive(
prediction(model, data(),t=200,window=seq(50,1900,50),
                                MC.sample=100))

output$hot <- renderRHandsontable({
    rhandsontable(datapred)
    })

data <- reactive({
      DF = hot_to_r(input$hot)
      DF
})

output$pred <- renderPlot({
plot(predict(),conf.bands=TRUE)
})

}
shinyApp(ui = ui, server = server)
1

1 Answers

0
votes

You could simply evaluate the data() first, like this. I also added some checks so you don't get other errors during the initialization

library(shiny)
library(frailtypack)
library(rhandsontable)
data("readmission", package = "frailtypack")

ui <- fluidPage(
  titlePanel("prediction"),

  mainPanel(
    fluidRow(rHandsontableOutput("hot")),
    br(),
    plotOutput("pred")
  )
)

server <- function(input, output) {

  newdata <- subset(readmission,select = c("time","event","id","dukes"))
  datapred <- newdata[1,]

  data <- reactive({
    hot <- input$hot
    if (!is.null(hot)) hot_to_r(hot)
  })

  model <- frailtyPenal(Surv(time,event)~cluster(id)+dukes,n.knots=10,
                        kappa=10000,data=readmission)

  predict <- reactive({
    dat <- data()
    if (!is.null(dat)) {
      prediction(model, dat,t=200,window=seq(50,1900,50),
                 MC.sample=100)
    }
  })

  output$hot <- renderRHandsontable({
    rhandsontable(datapred)
  })

  output$pred <- renderPlot({
    pred <- predict()
    if (!is.null(pred)) plot(pred, conf.bands = TRUE)
  })
}
shinyApp(ui = ui, server = server)