如何将闪亮的不同输入互连

时间:2017-06-05 13:28:42

标签: r shiny

我有一个dataset,其中有两列:pr,稍后我会根据用户输入过滤图表上的信息。用户将输入值(input$pnuminput$rat)或在滑块上选择它(input$pvalinput$ratio)。

  1. 如果输入数字输入,则滑块需要自动更新,反之亦然,如果用户在滑块上选择了值,则数字输入也会更新。
  2. 滑块的最小值和最大值是根据使用dataset$p的数据定义的,用于定义input$pvaldataset$r的最小值/最大值,以定义input$ratio的起始值。
  3. 在此之前,代码正在为我提供所需的输出。但是,我希望包含附加条件:当input$ratio的值发生变化时,应使用{{input$pval的最小值重新计算r>=input$ratio的最大值1}},以同样的方式,当input$pval更改为input$ratio的滑块上的用户最小/最大值时,应重新计算。

    添加这些条件会返回以下警告,并且滑块上会显示NaN而不是实际值。

    > Warning in max(dataset$r[which(-log10(as.numeric(dataset$p)) >=
    > input$pnum)],  :   no non-missing arguments to max; returning -Inf
    > Warning in
    > max(abs(log10(as.numeric(dataset$p[which(as.numeric(dataset$r) >=  :  
    > no non-missing arguments to max; returning -Inf Warning in
    > max(dataset$r[which(-log10(as.numeric(dataset$p)) >= input$pnum)],  : 
    > no non-missing arguments to max; returning -Inf Warning in
    > max(abs(log10(as.numeric(dataset$p[which(as.numeric(dataset$r) >=  :  
    > no non-missing arguments to max; returning -Inf
    

    代码:

    library(shiny)
    library(shinydashboard)
    
    
    sidebar <- dashboardSidebar(
      sidebarMenu(
            menuItem("Plot result", tabName = "scatterplot", icon = icon("area-chart"))
    ))
    
    body <- dashboardBody(
      tabItems(
        tabItem(tabName = "scatterplot", 
                fluidRow(
                  box(
                    uiOutput("rat"),
                    uiOutput("ratio"),
                    uiOutput("pnum"),
                    uiOutput("pval"),
                    width = 5
                  )
                )
        )
      )
    )
    
    
    ui=dashboardPage(
      dashboardHeader(title = "analysis"),
      sidebar,
      body
    )
    
    
    server=shinyServer(function(input, output, session) {
      dataset <- structure(list(p = c(6.03934743495282e-02, 1.50433174696588e-01, 
                                      2.08047037184403e-03, 5.89297106629446e-05, 0.000102485231497565, 
                                      0.0010651774924444, 0.0126458836222225, 0.000210364148948929, 
                                      0.00274720409905674, 0.281095738489031, 0.000316170681574214, 
                                      0.0316321461125659, 0.000369171267912158, 0.000369171267912158, 
                                      0.0395213746526263, 0.475174078010843, 0.000718770258398781, 
                                      0.760859052164441, 0.000810153915789446, 0.000875314011490406
      ), ratio_p_group_min = c(1.57380553778931, 1.11245772000324, 
                               1.504084996599, 1.00963266560562, 1.28098052443163, 1.49882201127675, 
                               1.10761702001084, 0.767267328293303, 1.03412495601202, 1.33508933929913, 
                               0.835478202626155, 0.998537147454481, 1.2008830437325, 1.2008830437325, 
                               1.15710746065582, 0.99677375722945, 1.37744067975694, 1.3666109673056, 
                               1.34583027836758, 1.34766012381264)), .Names = c("p", "r"
                               ), row.names = c(NA, 20L), class = "data.frame")
    
    
      output$rat <- renderUI({
            numericInput("rat","Define minumun ratio", value = input$ratio,step=0.01 , width = '40%')
      })   
    
      output$ratio <- renderUI({
        dataset <- dataset[which(!is.na(dataset$r)),]   
        #***this is the first line causing error
        maxkaw <- round(max(dataset$r[which(-log10(as.numeric(dataset$p))>=input$pnum)],na.rm=T),digits=2) 
        minkaw <- round(min(dataset$r,na.rm=T),digits=2)
        sliderInput("ratio",NULL, min   = minkaw, 
                    max   = maxkaw,
                    value = input$rat)
      })
    
      output$pnum <- renderUI({
        numericInput("pnum","-log10(P)", value = input$pval,step=0.001, width = '40%')
      })
    
      output$pval <- renderUI({
        dataset <- dataset[which(!is.na(dataset$r)),]
        #***this is the second line causing error
        maxpval <- round(max(abs(log10(as.numeric(dataset$p[which(as.numeric(dataset$r)>=input$rat)]))),na.rm=T),digits=2) 
        sliderInput("pval",NULL, min   = 0, 
                    max   = maxpval,
                    value = input$pnum)
      }) 
    })
    
    
    shinyApp(ui=ui, server=server)
    

0 个答案:

没有答案