Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shining-如何使用checkboxGroupInput筛选表和箱线图中的变量_R_Shiny - Fatal编程技术网

Shining-如何使用checkboxGroupInput筛选表和箱线图中的变量

Shining-如何使用checkboxGroupInput筛选表和箱线图中的变量,r,shiny,R,Shiny,我不知道如何使用checkboxGroupInput编写服务器代码来筛选变量选择。我想过滤将在箱线图和表中显示的变量。我在UI中添加了所有变量 我的代码:(我使用multi-multi.csv数据集) UI shinyUI(fluidPage( sidebarLayout( sidebarPanel( fileInput("fileInPath", label= h4("Import danych")), sliderInput("kolor", h4("Wy

我不知道如何使用checkboxGroupInput编写服务器代码来筛选变量选择。我想过滤将在箱线图和表中显示的变量。我在UI中添加了所有变量

我的代码:(我使用multi-multi.csv数据集)

UI

shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(
      fileInput("fileInPath", label= h4("Import danych")),
      sliderInput("kolor", h4("Wybierz kolor"),min = 0, max = 1, value = 0.5, step=0.05),
      checkboxGroupInput("kolumna", h4("Wybierz kolumny"), choices = c('L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'L8', 'L9', 'L10', 'L11', 'L12', 'L13','L14', 'L15', 'L16', 'L17', 'L18', 'L19', 'L20')),
      mainPanel(
      tabsetPanel(type = "tabs",
                  tabPanel("Table", tableOutput("daneIn")),
                  tabPanel("Plot", plotOutput("plot")),
                  tabPanel("Model", verbatimTextOutput("model"))))) ))
服务器

library(shiny)
library(ggplot2)
library(reshape)

model <- function(d){
  tmpTab <- table(as.integer(unlist((d[,-c(1:4)]))))
  ret <- as.integer(head(names(tmpTab[order(tmpTab,decreasing=T)]),10))
  ret <- as.data.frame(matrix(ret,ncol=1))
  return(ret)
}
shinyServer(function(input, output) {
  dataIn <- reactive({
    inFile <- input$fileInPath
    if (is.null(inFile)) {
      return(NULL)
    } read.table(file=inFile$datapath,sep=";",dec=",",header=T,stringsAsFactors=FALSE)
  })
  output$daneIn <- renderTable({
    ret <- rbind(
      head(dataIn(),5),
      tail(dataIn(),5)
    )
    return(ret)
  },include.rownames=FALSE)
  output$plot <- renderPlot({
    d <- dataIn()
    InColor <- rgb(as.numeric(input$kolor),0,0,1)
    d <- melt(d[,-c(2:4)],id.vars="Numer")
    wyk <- (
      ggplot(d,aes(x=variable,y=value)) 
      + geom_boxplot(color = InColor) 
      + xlab("") + ylab("Kula")
    ) 
    return(wyk)
  }) 
  output$model <- renderPrint({
    d <- dataIn()
    ret <- model(d)
    return(ret)
  }) 
  })
库(闪亮)
图书馆(GG2)
图书馆(重塑)

model您要做的是根据用户触发
复选框时应用的规则创建一个条件反应过滤器。我无法根据提供的代码推断规则,但我可以提出以下建议:

  • 将以下代码添加到服务器.R(其中“您的规则”指的是您要应用的筛选规则):

  • 现在,您将能够动态呈现已过滤和未过滤的数据


  • 我希望这能奏效。如果可行,请不要忘记投票:-)。

    @alicjaZ此解决方案有帮助吗?
    filteredData <- shiny::reactive({
    switch(
      input$kolumna,
      'L1' = dataIn() %>% filter(Your Rule), 
      'L2' = dataIn() %>% filter(Your Rule), 
      'L3' = dataIn() %>% filter(Your Rule), 
      'L4' = dataIn() %>% filter(Your Rule), 
      'L5' = dataIn() %>% filter(Your Rule), 
      'L6' = dataIn() %>% filter(Your Rule), 
      'L7' = dataIn() %>% filter(Your Rule), 
      'L8' = dataIn() %>% filter(Your Rule), 
      'L9' = dataIn() %>% filter(Your Rule), 
      'L10' = dataIn() %>% filter(Your Rule), 
      'L11' = dataIn() %>% filter(Your Rule), 
      'L12' = dataIn() %>% filter(Your Rule), 
      'L13' = dataIn() %>% filter(Your Rule),
      'L14' = dataIn() %>% filter(Your Rule), 
      'L15' = dataIn() %>% filter(Your Rule), 
      'L16' = dataIn() %>% filter(Your Rule), 
      'L17' = dataIn() %>% filter(Your Rule), 
      'L18' = dataIn() %>% filter(Your Rule), 
      'L19' = dataIn() %>% filter(Your Rule), 
      'L20' = dataIn() %>% filter(Your Rule)
      )
    })
    
    output$model <- renderPrint({
     # You have not selected any filters, hence your original upload will be rendered
     if (is.null(input$kolumna)) {
       d <- dataIn()
       ret <- model(d)
       return(ret)
     } else { # You have filtered your data, which filteredData() will handle
       d <- filteredData()
       ret <- model(d)
       return(ret)
     }
    })