Dear community,
The code below is working, however I want to make a ggsurvplot instead of a simple plot. However, it returns errors when I try to make the ggsurvplot. I have tried everything I know. Does someone know what the problem is?
I would be very grateful.
Kind regards,
R
# clear all:
rm(list = ls())
library(shiny)
library(shinydashboard)
library(survival)
library(table1)
library(KMsurv)
library(survminer)
Gender <- c("Male", "Male", "Male","Female", "Female", "Female","Female", "Female", "Female","Female", "Female", "Female")
Sidedness <- c("Left","Left","Left","Left","Left","Left","Right","Right","Right","Right","Right","Right")
Nationality <- c("French","French","French","French","French","German","German","German","German","German","German","German")
BRAF <- c("Wildtype","Wildtype","Mutated","Mutated","Mutated","Wildtype","Wildtype","Wildtype","Wildtype","Mutated","Mutated","Mutated")
RAS <- c("Mutated","Mutated","Mutated","Mutated","Mutated","Wildtype","Wildtype","Wildtype","Wildtype","Wildtype","Wildtype","Wildtype")
TI_Met_FUP <- c(5,20,100,60,40,30,30,2,180,270,40,200)
Death <- c(0,1,1,1,1,0,0,0,0,1,1,0)
data <- data.frame(Gender,Sidedness,Nationality,BRAF,RAS,TI_Met_FUP,Death)
#UI
ui <- dashboardPage(
dashboardHeader(title = "Survival analysis MSI mCRC"),
dashboardSidebar(),
dashboardBody(
box(plotOutput("survival_plot"), width = 8),
box(selectInput('sur_var', 'Factor of Survival', c("BRAF", "RAS")), width = 4
)
)
)
#Server
server <- function(input, output){
# Combine the selected variables into a new data frame
selectedData <- reactive({
data[, c(input$sur_var)]
})
# This is a caption that will show on top of the graph; the name will change based on which variable you choose
output$caption <- renderText({
paste("Survival Graph of", input$sur_var, sep="\n")
})
# Running the survival function
runSur <- reactive({
survfit(as.formula(paste("Surv(TI_Met_FUP, Death) ~",paste(input$sur_var))),data=data)
})
output$survival_plot <- renderPlot({
plot(runSur(),
col=c("red","sky blue"),
xlab = "Months",
ylab = "Overall survival probability",
xscale=30.5,
xlim=c(0,50))
})
}
shinyApp(ui, server)