Dear community,
If you could help me with one or both of the following questions, I would be very grateful. I have created a Shiny dashboard for an interactive table1 and survival curve and have two topics I am stuck with for a long time:
- Does anyone know how to get the 'print (fit)' into the Shiny Dashboard? Somehow it doesn't work for me.
- Does anyone know if the layout/CSS of table1 can be the same in Shiny dashboard as it is outside the Shiny dashboard? The layout changed when it is used in Shiny dashboard. One person of the community has looked into this before, for which I am grateful, but we couldn't figure it out.
If you need more information, please let me know. I would be very happy if I could fix above mentioned problems. Thanks in advance.
R
#Question for the community
library(shiny)
library(shinydashboard)
library(survminer)
library(survival)
library(table1)
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 <- dashboardPage(
dashboardHeader(title = "Project"),
dashboardSidebar(
sidebarMenu(
menuItem("Welcome", tabName = "Welcome", icon = icon("door-open")),
menuItem("Table1", tabName = "Table1", icon = icon("table")),
menuItem("OS", tabName = "OS", icon = icon("chart-line"))
)
),
dashboardBody(
tabItems(
tabItem("Welcome",
fluidPage(
h1("Welcome to the Shiny Dashboard"))
),
tabItem("Table1",
fluidPage(
box(uiOutput("T1")),
box(selectInput('cat_var', 'Variable', c("Gender", "Sidedness", "Nationality")))
)
),
tabItem("OS",
titlePanel("Survival Data"),
selectInput(inputId = "BRAF",label="Select BRAF:",c("All", unique(as.character(data$BRAF)))),
selectInput(inputId = "RAS",label="Select RAS:", c("All", unique(as.character(data$RAS)))),
plotOutput("p1"),
box(plotOutput("p2"))
)
)))
#Server
server <- function(input, output){
output$T1 = renderUI({
table1(formula(paste("~ Gender + Sidedness |", input$cat_var)), data=data,render.missing=NULL,
render.categorical="FREQ (PCTnoNA%)")
})
filter=reactive({
filteredData=data
if(input$BRAF != "All") {data <- data[data$BRAF == input$BRAF,]}
if(input$RAS != "All") {data <- data[data$RAS == input$RAS,]}
filteredData=data
return(filteredData)
})
output$p1=renderPlot({
fit <- survfit(Surv(TI_Met_FUP,Death)~1,data=filter())
ggsurvplot(fit,data=filter(),xlim=c(0,50), break.time.by =5,
title=paste(
input$BRAF,
input$RAS),
xlab="Time (Months)",
risk.table=TRUE,
surv.median.line = "hv",
ggtheme=theme(plot.title=element_text(hjust=0.5)))
})
output$p2=renderPlot({
fit <- survfit(Surv(TI_Met_FUP,Death)~1,data=filter())
print(fit)
})
}
shinyApp(ui, server)