I defined 'Time' in renderPlot(shiny) function. However, I get an
Error: object 'Time' not found.
I wonder that why I get this error as I already defined for the 'Time' variable
library(shiny)
library(survival)
library(survminer)
library(ggplot2)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file","File input"),
selectInput("Survival",
label = "Survival",
choices = c('time.day',
'time.year'),
selected = 'time.day'),
selectInput("Treatment",
"Treatment",
choices = c("trt"),
selected = "trt")
),
mainPanel(
plotOutput("KM")
)
)
)
server <- function(input, output) {
output$KM <- renderPlot({
req(input$file)
df <- read.csv(input$file$datapath)
df<- data.frame(df)
Time <- switch(input$Survival,
"time.day" = df$time.day,
"time.year" = df$time.yr)
x <- switch(input$Treatment,
"trt" = df$trt)
fit <- survfit(Surv(Time , cen) ~ x , data = df)
ggsurvplot(fit,risk.table = TRUE)
}
)
}
shinyApp(ui = ui, server = server)
The input data usually a csv file like:
time.yr time.day cen trt
1.181940686 431.7038355 0 1
3.174982816 1159.662473 1 1

Time? Also, R is case-sensitive to if you definetime(which is most likely the case as per "common" naming conventions in R programming) thentime!=Time. If that doesn't solve your issue, please provide a meaningful reproducible example - should be a relatively easy fix based on your question. - onlyphantom