What is the best way to render a regression table in shiny? I could generate a html table using stargazer
set.seed(1272015)
n<-1000
x1 <- rnorm(n = n, mean = 7, sd = 2)
x2 <- rnorm(n = n, mean = 4, sd = 2)
treatment <- sample(x = c(1,0), size = n, replace = T, prob=c(0.3,0.7))
y <- 2.1234*x1 + 1.1234*x2 + 0.5*treatment + rnorm(n, mean=0, sd=1)
mydata = data.frame(x1, x2, treatment, y)
lm1 <- lm(formula = y~x1+x2+treatment, data=mydata)
stargazer::stargazer(lm1, type="html")
but, I'm not sure how to render it in shiny. For example:
## app.R ##
library(shiny)
library(shinydashboard)
library(stargazer)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(title = "Regression table", renderUI(lm1))
)
)
)
server <- function(input, output) {
lm1 <- htmlOutput(stargazer(lm1, type="html"))
}
shinyApp(ui, server)