我正在尝试制作一个Shiny应用程序,该应用程序生成(样本大小)与(功效)的图。我的应用正确显示了用于用户输入的所有选项,但是无法显示我希望系统生成的图。
您能帮我吗?下面是我的代码:
ui <- fluidPage(
selectInput("diagType", "Diagnosis Outcome of Interest:", c("Cancer", "Sepsis", "SIRS")),
selectInput("alpha", "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=1, 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=1, max=25, value=12.5),
sliderInput("bin6", label = "Cut off level for Temp:", min=100, max=105, value=103)),
conditionalPanel( condition = "input.diagType == 'SIRS'",
sliderInput("bin7", label = "Cut off level for CNP:", min=1, max=16, value=8),
sliderInput("bin8", label = "Cut off level for Pulse:", min=95, max=180, value=135)),
plotOutput("plot")
)
output$plot <- renderPlot({
if (input$diagType=='Cancer'){
d <- data()
plot(d$power.vec, d$cancer.sample.size)
}
})
output$plot <- renderPlot({
if (input$diagType=='Sepsis'){
d <- data()
plot(d$power.vec, d$sepsis.sample.size)
}
})
output$plot <- renderPlot({
if (input$diagType=='SIRS'){
d <- data()
plot(d$power.vec, d$SIRS.sample.size)
}
})
}
shinyApp(ui, server)
答案 0 :(得分:0)
当您包含ui <- fluidPage
和shinyApp(ui, server)
时,我将假定这是您的完整代码?
我看不到您的服务器功能和数据选择部分。你可以包括吗?
我简化了您的代码,并为图表使用了cars
数据,它对我有用。我认为问题出在您的下拉菜单和数据生成d <- data()
之间。
library(shiny)
ui <- fluidPage(
selectInput("diagType", "Diagnosis Outcome of Interest:", c("Cancer", "Sepsis", "SIRS")),
selectInput("alpha", "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=1, max=12, value=6),
sliderInput("bin3", label = "Cut off level for BW:", min=1, max=40, value=20)),
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
if (input$diagType=="Cancer"){
d <- cars
plot(d$speed, d$dist)
}
})
}
shinyApp(ui, server)