0

I have a data frame with three columns:

x = data.frame(group=c("group1", "group2", "group3","group1","group3", "group4", "group2"),
               user=c("user1", "user3", "user5", "user9", "user14", "user18", "user24"),
               erro=c("error1", "error2", "error4", "error3", "error2", "error1", "error3") 
               )
x

I need to create a shiny app that shows in data table a list of rows from that table which have only error2 and error3. As a control widget I need a filter of group type. How could i built it? I'm new in shiny.

  • hi, I can only invite you to read some [tutorials](https://shiny.rstudio.com/tutorial/written-tutorial/lesson1/) on R shiny, it will be more efficient than asking questions on StackOverflow. Also, several similar questions have already been asked on this topic, you should search online and if you don't find any information, then ask what you're looking for on StackOverflow – bretauv Jan 26 '20 at 22:31
  • @bretauv well stackoverlow is handy in case if your code doesn't work and also there's not much of a questions like this here so it would be useful to add some case –  Jan 26 '20 at 22:36
  • the most unclear part for me here is filtering data by group(control widget) –  Jan 26 '20 at 22:39
  • well if you want to ask a question, you should add a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). For a question about R shiny, you should add the code necessary to reproduce your app, i.e the ```ui``` and ```server``` part. Try to reduce this code as much as possible because not all components are necessary. Also, making the effort of simplifying our problem is a great way to find the solution on our own – bretauv Jan 26 '20 at 22:41
  • 1
    @EdZ there really are a number of ways you could approach this, and more details would be helpful. Take a look at 'selectInput` which offers `multiple` option, or `checkboxGroupInput` for checkboxes, or `DT` library for `datatable` that can be filtered with `regex` to handle various complex filters. Based on inputs you can make a `reactive` expression to handle what rows are displayed in your data table based on these input selections. If you haven't already look at the [gallery](https://shiny.rstudio.com/gallery/) of examples or view a tutorial to get ideas. – Ben Jan 27 '20 at 00:22
  • code example would be nice though –  Jan 27 '20 at 09:17
  • @EdZ almost every option proposed by Ben are in the tutorials I talked about in the first comment, you should really follow them – bretauv Jan 27 '20 at 12:11

1 Answers1

1

Here's a start:

library(shiny)
library(dplyr)

x = data.frame(group=c("group1", "group2", "group3","group1","group3", "group4", "group2"),
               user=c("user1", "user3", "user5", "user9", "user14", "user18", "user24"),
               erro=c("error1", "error2", "error4", "error3", "error2", "error1", "error3") 
)

ui = fluidPage(
  selectInput("grType", "Select group type", x$group, multiple = TRUE),
  tableOutput("myTable")
)

server <- shinyServer(function(input, output, session) {
  output$myTable <- renderTable({
    req(input$grType)
    x %>% filter(group %in% input$grType, 
                 erro %in% c("error2", "error3"))
  }) 
}
)
shinyApp(ui = ui, server = server)

motch
  • 458
  • 4
  • 13
  • thanks, is it possible also to choose all groups simultaneously in control widget? –  Jan 27 '20 at 20:15
  • @EdZ sure, add ```multiple = TRUE``` in ```selectInput``` – bretauv Jan 27 '20 at 20:27
  • We also need to change filtering method to ```group %in% input$grType``` if we want multiple inputs. I added that to my respons – motch Jan 27 '20 at 20:36