条件面板中带数字输入的单选按钮

时间:2017-08-22 23:00:25

标签: r shiny radio-button conditional

我正在尝试制作一个Shiny应用程序来进行计算,就像在[这篇论文中一样] 有3种计算方法,称为“calcprior”,“calcpval”和“calcFPR”。

radioButton选择进行哪种计算。每次计算需要不同的输入。输入放在conditionalPanels中。正确的名称出现在c onPanelPanel中,但数值不会传递给服务器,例如input $ pval没有在条件面板的numericInput中输入的值。

相比之下,所有3次计算所需的nsamp值都正确传递给服务器。

我是Shiny的初学者,所以我希望有人可以解释出了什么问题。无法看到变量的值使得调试比普通R更难以百万倍。

    sidebarLayout(

    sidebarPanel(
     radioButtons("calctype", "Choose calculation:",selected = "calcFPR", 
     choices = c(
    "prior (for given FPR and P val)" = "calcprior",
    "P value (for given FPR and prior)" = "calcpval",    
     "FPR (for given P value and prior)" = "calcFPR")),

    conditionalPanel(
     condition = "input.calctype == 'calcprior'",
     numericInput("pval", label = h5("observed P value"), value = 0.05, min 
    = 0, max = 1),
     numericInput("FPR", label = h5("false positive risk"), value = 0.05, 
     min = 0, max = 1)
     ),

    conditionalPanel(
     condition = "input.calctype == 'calcpval'",
      numericInput("FPR", label = h5("false positive risk"), value = 0.05, 
      min = 0, max = 1),
      numericInput("prior", label = h5("prior probability of real effect"), 
     value = 0.5, min       = 0, max = 1)
     ),

    conditionalPanel(
     condition = "input.calctype == 'calcFPR'",
      numericInput("pval",label = h5("observed P value"),value = 0.05, min = 
      0, max = 1),
      numericInput("prior", label = h5("prior probability of real effect"), 
      value = 0.5, min = 0., max = 1.)
      ),

     inputPanel(
      numericInput("nsamp",label = h5("Number in each sample"), step = 1, 
      value = 16, min = 2)
    ),

    mainPanel(

(我还需要弄清楚如何使用calctype将服务器定向到适当的R代码块。)

1 个答案:

答案 0 :(得分:0)

以下是您的工作示例:

ImageCollection

你不需要那么多library(shiny) ui <- fluidPage( titlePanel("|Species Table"), sidebarLayout( sidebarPanel( radioButtons("calctype", "Choose calculation:",selected = "calcFPR", choices = c( "prior (for given FPR and P val)" = "calcprior", "P value (for given FPR and prior)" = "calcpval", "FPR (for given P value and prior)" = "calcFPR")), uiOutput("test1"), uiOutput("test2"), inputPanel( numericInput("nsamp",label = h5("Number in each sample"), step = 1, value = 16, min = 2) )), mainPanel(textOutput("text1"), textOutput("text2")) )) server <- function(input, output) { test <- reactive({ if(input$calctype == 'calcprior'){ label1 <- paste("observed P value") label2 <- paste("false positive risk") }else if(input$calctype == 'calcpval'){ label1 <- paste("false positive risk") label2 <- paste("prior probability of real effect") }else{ label1 <- paste("observed P value") label2 <- paste("prior probability of real effect") } list(label1 = label1, label2 = label2) }) output$test1 <- renderUI({ numericInput("test1", label = h5(test()$label1), value = 0.05, min = 0, max = 1) }) output$test2 <- renderUI({ numericInput("test2", label = h5(test()$label2), value = 0.05, min = 0, max = 1) }) output$text1 <- renderText({ input$test1 }) output$text2 <- renderText({ input$test2 }) } shinyApp(ui = ui, server = server) ,我在你的代码中注意到,根据选择的计算类型,唯一改变的是conditionalPanels的标签。因此,在这种情况下,我使用numericInput中的if...else...语句来更改两个`numericInputs(test1和test2)的标签,并选择计算类型。

此外,我打印出server的输出(text1和text2),以显示用户输入是实际传递给服务器的,可以进一步用于计算。