Display selected rows in the next tab

I am facing a issue here. Below is the simple app, i am trying to get below output but not getting. can anyone please help. 1) When I select iris, in Page1 and Page2, the iris dataset is displayed that is fine. So from here if I select any specific row (In Page1), that specific row should be displayed in the next tab (Page 2). For example refer below . Is it possible to have 6th row(selected) in the next tab (page2). Similarly Once I unselect iris data set, All datasets should disappear. is it possible to achieve this?

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
```

Page 1
===================================== 

### Chart A

```{r}
selectInput("dataset","Select",choices = c("","iris","mtcars"))
DT::DTOutput('table1')
datasetInput <- reactive({
    switch(input$dataset,
           "iris" = iris,
           "mtcars" = mtcars)
  })
output$table1 <- DT::renderDT({
    head(datasetInput(), n = 10)
  })
```

Page 2
=====================================     

### Reactive

```{r}
DT::DTOutput('table2')
datasetInput <- reactive({
    switch(input$dataset,
           "iris" = iris,
           "mtcars" = mtcars)
  })
output$table2 <- DT::renderDT({
    head(datasetInput(), n = 100)
  })

Hi,

Here is my implementation:

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
```

Page 1
===================================== 

### Chart A

```{r}
selectInput("dataset","Select",choices = c("","iris","mtcars"), selected = "iris")
DT::DTOutput('table1')
datasetInput <- reactive({
    switch(input$dataset,
           "iris" = iris,
           "mtcars" = mtcars)
  })
output$table1 <- DT::renderDT({
    head(datasetInput(), n = 10)
  })
```

Page 2
=====================================     

### Reactive

```{r}
DT::DTOutput('table2')
datasetInput <- reactive({
    switch(input$dataset,
           "iris" = iris,
           "mtcars" = mtcars)
  })
output$table2 <- DT::renderDT({
    if(is.null(input$table1_rows_selected)){
      
    } else {
      head(datasetInput()[input$table1_rows_selected,], n = 100)
    }
    
  })
```
  • All I did was use the datatable's rows_selected feature and used it to filter the dataframe in the second tab (datasetInput()[input$table1_rows_selected,])
  • Also, I set the iris dataset as the default option in tab 1 as you should not have empty selections in a dropbox

Hope this helps,
PJ

1 Like

Awesome thanks. This is what I wanted

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.