我正在尝试在我的R Shiny应用程序上显示反应式ggplot,但是它不起作用,我不确定为什么。如果有人可以指出为什么它不起作用,将不胜感激。
下面是我的代码:
1。 ui
ui <- fluidPage(titlePanel("Sample Size Calculator for Binary Covariates from Dog Data Based on Heish et. al (1998)"),
helpText("This sample size Calculator is based on the paper 'A Simple Method of Sample Size Calculation for Linear and Logistic Regression' by Heish et al. (1998)",
"This calculator treats each covariate as a binary variable, based on the cutoff point of your choice.",
"The set of covariates considered in the model are those set of covariates in which their desirable cutoff levels were successfully identified by their ROC curves. ",
"Please select Significance Level, and Cutoff Levels of each covariate that you would like to implement. The plot of Sample Size vs. Power will be displayed below:"),
selectInput("diagType", "Diagnosis Outcome of Interest:", c("Cancer", "Sepsis", "SIRS")),
selectInput("alpha1", "Significance Level:", c("0.05", "0.01", "0.001")),
conditionalPanel( condition = "input.diagType == 'Cancer'",
sliderInput("bin1", label = "Cut off level for TK:", min=1, max=20, value=10),
sliderInput("bin2", label = "Cut off level for AGE:", min=3, max=12, value=6),
sliderInput("bin3", label = "Cut off level for BW:", min=1, max=40, value=20)),
conditionalPanel( condition = "input.diagType == 'Sepsis'",
sliderInput("bin4", label = "Cut off level for CRP:", min=1, max=45, value=22.5),
sliderInput("bin5", label = "Cut off level for WBC:", min=13, max=25, value=12.5),
sliderInput("bin6", label = "Cut off level for Temp:", min=103, max=106, value=103)),
conditionalPanel( condition = "input.diagType == 'SIRS'",
sliderInput("bin7", label = "Cut off level for CNP:", min=7, max=16, value=8),
sliderInput("bin8", label = "Cut off level for Pulse:", min=104, max=180, value=135)),
mainPanel(plotOutput("plot"))
)
2。服务器
server <- function(input, output) {
d <- reactive({
power.vec = c(0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95)
if(input$diagType == "Cancer"){
a = input$alpha1
b1 = input$bin1
b2 = input$bin2
b3 = input$bin3
e<-calculator.cancer(a,b1,b2,b3)
}
if(input$diagType == "Sepsis"){
a = input$alpha1
b4 = input$bin4
b5 = input$bin5
b6 = input$bin6
e<-calculator.sepsis(a,b4,b5,b6)
}
if(input$diagType == "SIRS"){
a = input$alpha1
b7 = input$bin7
b8 = input$bin8
e <-calculator.sirs(a,b7,b8)
}
})
output$plot <- renderPlot({
b <- d()
p <- ggplot(b, aes(x = power.vec, y = e) + labs(
x = "Level of Power",
y = "Sample Size",
title = "Plot of Sample Size versus Power") + geom_point() + geom_line())
print(p)
})
}
shinyApp(ui, server)
为什么我的ggplot无法显示?谢谢