Как-то так?
library(shiny)
library(dplyr)
library(reshape2)
library(tidyr)
library(DT)
ui <- fluidPage(
headerPanel("Summary Table"),
sidebarPanel(selectInput("row", "Row variable", names(mtcars), selected = "vs", multiple = T),
selectInput("col", "Column variable", names(mtcars), selected = "gear")),
mainPanel(DT::dataTableOutput('table'))
)
server <- function(input, output) {
output$table <- renderDataTable({
car0 <- mtcars %>%
select(input$row,input$col,cyl)%>%
group_by_at(., vars(input$row, input$col))%>%
summarize(n = n_distinct(cyl))%>%
tidyr::spread(input$col,n)
datatable(car0)
})
}
shinyApp(ui, server)
для формулы и reshape2
library(shiny)
library(dplyr)
library(reshape2)
library(tidyr)
library(DT)
ui <- fluidPage(
headerPanel("Summary Table"),
sidebarPanel(selectInput("row", "Row variable", names(mtcars), selected = "vs", multiple = T),
selectInput("col", "Column variable", names(mtcars), selected = "gear")),
mainPanel(DT::dataTableOutput('table'))
)
server <- function(input, output) {
output$table <- renderDataTable({
formula <- as.formula(paste(paste(input$row, collapse = "+"), "~", input$col))
print(formula)
car0 <- mtcars %>%
select(input$row,input$col,cyl)%>%
group_by_at(., vars(input$row, input$col))%>%
summarize(n = n_distinct(cyl))%>%
#tidyr::spread(input$col,n)
dcast(formula, value.var = "n")
datatable(car0)
})
}
shinyApp(ui, server)