Created
September 5, 2014 13:22
-
-
Save cdeterman/fbe5f2821aaae1bc75b1 to your computer and use it in GitHub Desktop.
shared datatable between tabs?
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
library(shiny) | |
runApp(list( | |
ui = fluidPage( | |
tags$head(tags$style("tfoot {display: table-header-group;")), # move filters to the tob of dataTable | |
sidebarLayout( | |
sidebarPanel("Sharing Data between Tabs"), | |
mainPanel( | |
tabsetPanel( | |
id="tabs", | |
tabPanel("iris", | |
dataTableOutput("mytable")), | |
tabPanel("regression", | |
# print coefficient table | |
uiOutput("model_text"), | |
tableOutput("regTab")) | |
) | |
) | |
) | |
), | |
server = function(input, output) { | |
df <- reactive({ | |
iris[sample(nrow(iris)),] | |
}) | |
output$mytable = renderDataTable( | |
df() | |
) | |
# Linear Regression | |
runRegression <- reactive({ | |
df <- as.data.frame(df()) | |
# run regression | |
lm(df$Petal.Length ~ df$Petal.Width) | |
}) | |
# anova table | |
output$model_text <- renderUI({ | |
h3("Model Coefficient Table") | |
}) | |
# Coefficient Table | |
output$regTab <- renderTable({ | |
lm_sum <- summary(runRegression()) | |
coefs <- as.data.frame(lm_sum$coefficients) | |
coefs[,4] <- signif(coefs[,4], 4) | |
coefs[,4] <- as.character(coefs[,4]) | |
coefs | |
}, digits=4) | |
} | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you find a solution for this? Thanks