Skip to content

Instantly share code, notes, and snippets.

@ptoche
Last active January 3, 2016 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptoche/8385584 to your computer and use it in GitHub Desktop.
Save ptoche/8385584 to your computer and use it in GitHub Desktop.
Demo on matrixInput from package shinyIncubator
# server.R
library("shiny")
library("shinyIncubator")
shinyServer(
function(input, output) {
# table of outputs
output$table <- renderTable({
res <- matrix(apply(input$data,1,prod))
res <- do.call(cbind, list(input$data, res))
colnames(res) <- c("Input 1","Input 2","Product")
res
}
, include.rownames = FALSE
, include.colnames = TRUE
, align = "cccc"
, digits = 2
, sanitize.text.function = function(x) x
)
}
)
# ui.R
library("shiny")
library("shinyIncubator")
# initialize data with colnames
df <- data.frame(matrix(c("0","0"), 1, 2))
colnames(df) <- c("Input1", "Input2")
shinyUI(
pageWithSidebar(
headerPanel('matrixInput from shinyIncubator package - Demo')
,
sidebarPanel(
# customize display settings
tags$head(
tags$style(type = "text/css"
, "table.data { width: 300px; }"
, ".well {width: 80%; background-color: NULL; border: 0px solid rgb(255, 255, 255); box-shadow: 0px 0px 0px rgb(255, 255, 255) inset;}"
, ".tableinput .hide {display: table-header-group; color: black; align-items: center; text-align: center; align-self: center;}"
, ".tableinput-container {width: 100%; text-align: center;}"
, ".tableinput-buttons {margin: 10px;}"
, ".data {background-color: rgb(255,255,255);}"
, ".table th, .table td {text-align: center;}"
)
)
,
wellPanel(
h4("Input Table")
,
matrixInput(inputId = 'data', label = 'Add/Remove Rows', data = df)
,
helpText("This table accepts user input into each cell. The number of rows may be controlled by pressing the +/- buttons.")
)
)
,
mainPanel(
wellPanel(
wellPanel(
h4("Output Table")
,
tableOutput(outputId = 'table')
,
helpText("This table displays the input matrix together with the product of the rows of the input matrix")
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment