Last active
January 3, 2016 00:49
-
-
Save ptoche/8385584 to your computer and use it in GitHub Desktop.
Demo on matrixInput from package shinyIncubator
This file contains hidden or 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
# 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 | |
) | |
} | |
) |
This file contains hidden or 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
# 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