Skip to contents

Cell selection (in shiny)

Usage

grid_selection_cell(grid, inputId, selectionUnit = c("cell", "row"))

Arguments

grid

A table created with datagrid().

inputId

The input slot that will be used to access the value.

selectionUnit

The unit of selection on grid.

Value

A datagrid htmlwidget.

Examples

if (interactive()) {
  library(shiny)
  library(toastui)

  ui <- fluidPage(
    tags$h2("datagrid cell selection"),
    datagridOutput("grid_1"),
    verbatimTextOutput("result_1"),
    datagridOutput("grid_2"),
    verbatimTextOutput("result_2")
  )

  server <- function(input, output, session) {

    df <- data.frame(
      index = 1:12,
      month = month.name,
      letters = letters[1:12]
    )

    output$grid_1 <- renderDatagrid({
      datagrid(df) %>%
        grid_selection_cell(
          inputId = "cells"
        )
    })
    output$result_1 <- renderPrint({
      input$cells
    })

    output$grid_2 <- renderDatagrid({
      datagrid(df) %>%
        grid_selection_cell(
          inputId = "rows",
          selectionUnit = "row"
        )
    })
    output$result_2 <- renderPrint({
      input$rows
    })
  }

  shinyApp(ui, server)
}