library(shiny)
library(DT)
#----------------------------------------------------------------------------------------------------
# printf <- function(...) print(noquote(sprintf(...)))
#----------------------------------------------------------------------------------------------------
ui <- fluidPage(
fluidRow(
column(10,
actionButton("displayTableButton", "Display Table, then click on rows",
style="margin: 20px"),
h3(textOutput("rowCountTextOutput"), style="margin-left: 100px"),
div(DT::dataTableOutput("tableDisplay"), style="margin: 20px")
)
) # fluidRow
) # fluidPage
#----------------------------------------------------------------------------------------------------
server <- function(input, output)
{
observeEvent(input$tableDisplay_rows_selected, {
selectedTableRow <- isolate(input$tableDisplay_rows_selected)
output$rowCountTextOutput <- renderText(sprintf("row %d", selectedTableRow))
#printf("row click!");
#printf("selectedTableRow: %d", selectedTableRow)
}) # observe row selection event
observeEvent(input$displayTableButton, {
output$tableDisplay <- DT::renderDataTable(mtcars[1:8,],
width="800px",
class='nowrap display',
selection="single",
extensions="FixedColumns",
options=list(scrollX=TRUE,
scrollY="500px",
dom='t',
paging=FALSE,
autoWdth=FALSE,
fixedColumns=list(leftColumns=1)
))
}) # observer button
} # server
#----------------------------------------------------------------------------------------------------
app <- shinyApp(ui, server)
# enable this next line only for non-docker bash invocation use
# runApp(app)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.