R Shiny循环逻辑运算符

时间:2018-01-01 00:58:56

标签: r loops shiny logical-operators

我有一个正在运行的示例:我正在更新data.table,具体取决于用户通过复选框输入。到目前为止,我明确地过滤了数据,但我希望借助于使用for循环或apply-family函数的循环来实现。不幸的是,我无法上班。

library(shiny)
library(data.table)
library(DT)

tdata <- data.table(fruit = c(rep("Apple",4),rep( "Ban",4)), 
                    bug1 = c(rep(c("+","+", "-","-"),2)),
                    bug2 = c(rep(c("+","-"),4)),
                    value = c(rep(c(0.25),4), 0.6,0.4,0,0))

ui <- (fluidPage(tagList(
             sidebarLayout(
               sidebarPanel(uiOutput("file_input")),
               mainPanel(dataTableOutput('fruit_table')) 
      ))))

server <- function(input, output) {

  fileData <- reactive(
      return(tdata)
  )

  colname_list <- reactive( 
    colnames(fileData())
  )


  output$file_input <- renderUI ({
    if(is.null(fileData())){
      return()
    }else{
      tagList(
        lapply(1:(length(fileData())-1), function(i){
        choice_list = unique(fileData()[,get(colnames(fileData()[,i, with = FALSE]))])
        checkboxGroupInput(inputId = colnames(fileData()[,i, with = FALSE]),
                           label = colnames(fileData()[,i, with = FALSE]),
                           choices = choice_list,
                           inline = TRUE,
                           selected = fileData()[1, i, with = FALSE])
        })
      )
    }
  })

 # works fine, but usually the number of columns changes so I want to keep it flexible       


  fruitFilter <- reactive({
    fileData()[[paste0(colname_list()[1])]] %in% input[[paste0(colname_list()[1])]] &
      fileData()[[paste0(colname_list()[2])]] %in% input[[paste0(colname_list()[2])]] &
      fileData()[[paste0(colname_list()[3])]] %in% input[[paste0(colname_list()[3])]]
  })

  # fruitFilter <- reactive({
  #     for(i in 1: ((length(fileData()))-1)){
  #       fileData()[[paste0(colname_list()[i])]] %in% input[[paste0(colname_list()[i])]]
  #     }
  #  })

  output$fruit_table <- renderDataTable({
    datatable(fileData()[fruitFilter(),])
  })

}

shinyApp(ui = ui, server = server)

我仍然认为自己是Shiny的新手。我感谢任何帮助!感谢。

1 个答案:

答案 0 :(得分:1)

在循环方法中,我们可以将1. Choose correct .apk file from your system. 2. Upload and Decompile apk. 3. After sometime apk will be decompile and you will get source code of it. 4. Refer AndroidMenifest.xml file and find launcher tag in menifest, And mention activity which using this tag is the activity you want. 初始化,然后将list输出初始化为单个Reduce向量

logical

使用完整代码

fruitFilter <- reactive({

       i1 <- head(seq_along(fileData()), -1)
       l1 <- vector('list', length(i1))
       for(i in i1){

         l1[[i]] <- fileData()[[colname_list()[i]]] %in% input[[colname_list()[i]]]

       }

       Reduce(`&`, l1)
    })

- 输出

enter image description here