Skip to content

Instantly share code, notes, and snippets.

@cdeterman
Created September 5, 2014 13:22
Show Gist options
  • Save cdeterman/fbe5f2821aaae1bc75b1 to your computer and use it in GitHub Desktop.
Save cdeterman/fbe5f2821aaae1bc75b1 to your computer and use it in GitHub Desktop.
shared datatable between tabs?
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)
}
))
@avilella
Copy link

Did you find a solution for this? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment