How to remove that useless long page (or how to improve this code)?

Viewed 35

I've been working on Shiny RMD for a while, and I always have this kind of kinky issues. Here, I've got a whole page about the Shiny Session environment, and it bothers me. Any idea how to remove (or hide)? Below is my functioning code.

Kindest regards and thanks in advance,

Edit: Thanks to @shafee, I've managed to fix. Code above.

---
title: "Lab"
author: "Unknown"
date: "`r Sys.Date()`"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{r}
l <- NULL
l$name <- c('b','e','d','b','b','d','e')
l$age <- c(20,20,21,21,20,22,22)
l <- as.data.frame(l)
l$name <- as.character(l$name)
l$age <- as.numeric(l$age)
```

```{r}
selectInput("Box1","Choose a name", choices = c("All",unique(l$name)))
selectInput("Box2","Choose an age", choices = c("All",unique(l$age)))
```

```{r}
data1 <- reactive({
    if(input$Box1 == "All"){
      l
    }else{
      l[which(l$name == input$Box1),]
    }
  })

  data2 <- reactive({
    if (input$Box2 == "All"){
      l
    }else{
      l[which(l$age == input$Box2),]
    }
  })

    data3 <- reactive({
    if(input$Box2 == "All"){
      data1()
    }else if (input$Box1 == "All"){
      data2()
    }else if (input$Box2 == "All" & input$Box1 == "All"){
      l
    }
    else{
      l[which(l$age== input$Box2 & l$name == input$Box1),]
    }
  })
```

```{r}
  observeEvent(c(input$Box1,input$Box2),{

    if(input$Box1 != "All"){
      updateSelectInput(session,"Box2","Choose an age", choices = c("All",unique(data1()$age)))
    }

    else if(input$Box2 != 'All'){
      updateSelectInput(session,"Box1","Choose a name", choices = c('All',unique(data2()$name)))
    }

    else if (input$Box1 == "All" & input$Box2 == "All"){
      updateSelectInput(session,"Box2","Choose an age", choices = c('All',unique(l$age)))
      updateSelectInput(session,"Box1","Choose a name", choices = c('All',unique(l$name)))
    }
  })
```

```{r}
renderTable({
    data3()
  })
```
0 Answers
Related