Created
June 5, 2019 18:27
-
-
Save strboul/e2a273e620fba6519792ff1dc5dec206 to your computer and use it in GitHub Desktop.
Shiny create HTML tables #htmltools #tags #table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, much appreciated <3