如何解决R Shiny-如何对数据框进行子集化,保存子集化后的数据框,打印摘要信息?
我对 Shiny Apps 非常陌生。到目前为止,我的目标是为用户提供一个下拉菜单,他们可以在其中选择按年份列对数据框进行子集化(我希望我可以添加一个无子集选项)。这工作正常,但是,它看起来并不漂亮(它显示了所有行,没有以只显示头部然后有多个页面到数据框的方式进行格式化)。然后,我尝试获取要打印的列数和行数,我一直在为此苦苦挣扎。修复此问题后,我希望用户可以下载子集数据框。有什么建议吗?
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("World Happiness Report Data"),tags$h3("DS 3002,Project One"),tags$h4("By Jasmine Dogu (ejd5mm)"),sidebarLayout(
sidebarPanel(
selectInput('year',"Choose a Year",choices = sort(data$year,decreasing = TRUE),tableOutput("table1")
),mainPanel(
DT::dataTableOutput('contents'),verbatimTextOutput('summary'),plotOutput('plot')
)
)
)
)
# Define server logic required to subset data
server <- function(input,output) {
data <- read.csv("world-happiness-report.csv")
category <- data$year
df_subset <- reactive({
a <- subset(data,category==input$year)
return(a)
})
output$table1 <- renderTable(df_subset()) #Note df_subset() was used and not df_subset
output$contents <- DT::renderDataTable({
DT::datatable(df_subset())
})
output$summary <- renderPrint({
summary(df_subset())
})
}
# Run the application
shinyApp(ui = ui,server = server)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。