Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

Having issues appending tab on cell click within observeEvent function in R Shiny

$
0
0

This is the minimum reproducible example needed to help:

ui.R

library(shiny)

fluidPage(
  title = 'DataTables Information',
  tabsetPanel(id = "tabs",
                    tabPanel("Cars overview",
                             h1("Cars overview"),
                             div("Click any cell"),
                             br(),
                             DT::dataTableOutput("x4")
                    )
        )
)

Server script:

server.R
library(shiny)
library(DT)

shinyServer(function(input, output, session) {

  output$x4 = DT::renderDataTable({
    DT::datatable(mtcars, selection = 'single')
  }, server = TRUE) 



  observeEvent(input$x4_cells_clicked, {
    print("Trigger")
    value <- x4_cells_clicked$value
    details <- mtcars %>%
        filter(mpg == value)
    appendTab(inputId = "tabs",
              tabPanel(
                  DT::renderDataTable(DT::datatable(details), server = TRUE)

              )
    )
    # Focus on newly created tab
    updateTabsetPanel(session, "tabs", selected = "Car details")

  })

})

What I am trying to accomplish is to trigger an event through a cell click on the mtcars dataframe. I want to append a tab upon a click and filter the dataframe that is produced by the value within the cell that is clicked. I know in this case I am only accounting for a click on the mpg column but I just need to see how a click on a cell is registered through observeEvent and how to use the value of the cell clicked to filter the dataframe that is produced in the new tab.


Viewing all articles
Browse latest Browse all 201919

Trending Articles