Skip to content

Instantly share code, notes, and snippets.

@strboul
Created June 5, 2019 18:27
Show Gist options
  • Save strboul/e2a273e620fba6519792ff1dc5dec206 to your computer and use it in GitHub Desktop.
Save strboul/e2a273e620fba6519792ff1dc5dec206 to your computer and use it in GitHub Desktop.
Shiny create HTML tables #htmltools #tags #table
library(shiny)
ui <- fluidPage(
tags$head(
tags$style(HTML("
body {
margin-right: 10em;
margin-left: 10em;
}
table, th, td {
border: 1px solid black;
}
"))
),
h1("HTML Tables"),
br(),
fluidRow(
uiOutput("table"),
br(),
verbatimTextOutput("details")
)
)
server <- function(input, output, session) {
output$table <- renderUI({
tags$table(
style = "width:100%",
tags$tr(
tags$th("Name"),
tags$th("Surname"),
tags$th("Details")
),
tags$tr(
tags$td("John"),
tags$td("Doe"),
tags$td(actionButton("details_john_doe", "", icon = icon("search")))
),
tags$tr(
tags$td("Marie"),
tags$td("Antoinette"),
tags$td(actionButton("details_marie_antoinette", "", icon = icon("search")))
)
)
})
observeEvent(input$details_john_doe, print("John Doe, Age: 34"))
observeEvent(input$details_marie_antoinette, print("Marie Antoniette, Age: 25"))
}
## Source: https://www.w3schools.com/html/html_tables.asp
shinyApp(ui, server)
@annahuynhly
Copy link

thanks, much appreciated <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment