Created
January 1, 2014 11:34
-
-
Save anonymous/8207166 to your computer and use it in GitHub Desktop.
matrixInput function from shinyIncubator package demo
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
# server.R | |
shinyServer( | |
function(input, output) { | |
# table of outputs | |
output$table.output <- 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 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('devtools') | |
#install_github('shiny-incubator', 'rstudio') | |
library("shinyIncubator") | |
# initialize data with colnames | |
df <- data.frame(matrix(c("0","0"), 1, 2)) | |
colnames(df) <- c("Input1", "Input2") | |
shinyUI( | |
pageWithSidebar( | |
headerPanel('Simple matrixInput example') | |
, | |
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.output') | |
, | |
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