R 如何在处理csv文件后添加带有统计信息的节
我正在用Shinny做一个实验,上传一个csv文件,处理它,并显示两个不同的东西:1)数据的摘要分析,2)遵循一些特定条件的值列表,代码如下:R 如何在处理csv文件后添加带有统计信息的节,r,shiny,shinyapps,R,Shiny,Shinyapps,我正在用Shinny做一个实验,上传一个csv文件,处理它,并显示两个不同的东西:1)数据的摘要分析,2)遵循一些特定条件的值列表,代码如下: library(shiny) library(DT) library(sqldf) library(data.table) # Define UI ui <- shinyUI(fluidPage( h1("Sample Report"), h1(""), fileInput(
library(shiny)
library(DT)
library(sqldf)
library(data.table)
# Define UI
ui <- shinyUI(fluidPage(
h1("Sample Report"),
h1(""),
fileInput(
'target_upload',
'Choose file to upload',
accept = c('text/csv',
'text/comma-separated-values',
'.csv')
),
radioButtons(
"separator",
"Separator: ",
choices = c(","),
selected = ",",
inline = TRUE
),
DT::dataTableOutput("sample_table"),
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),
))
# Define server logic
server <- shinyServer(function(input, output) {
df_products_upload <- reactive({
inFile <- input$target_upload
if (is.null(inFile))
return(NULL)
df <-
read.csv(inFile$datapath,
header = TRUE,
sep = input$separator)
return(df)
})
output$sample_table <- DT::renderDataTable({
df <- df_products_upload()
pros <-
sqldf('select * from df where XXXX="any value" AND XX > 2 ')
qual <-
sqldf('select * from df where YYYY="any value" AND XX > 2 ')
AllDataIssue <-
rbind(pros,
qual)
DT::datatable(
{ AllDataIssue },
caption = htmltools::tags$caption(
style = 'caption-side: bottom; text-align: center;',
'Table 1: ', htmltools::em('Any message.')
),
extensions = 'Buttons',
options = list(
fixedColumns = TRUE,
autoWidth = TRUE,
ordering = TRUE,
dom = 'Bftsp',
filter = 'top',
buttons = c('csv', 'excel')
))
})
})
# Run the application
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(DT)
库(sqldf)
库(数据表)
#定义用户界面
ui您可以使用包含过滤数据的反应式,然后使用renderPrint输出其摘要:
在UI中添加以下内容:
textOutput("summary"),
然后更换服务器
AllDataIssue <- reactive({
df <- df_products_upload()
pros <-
sqldf('select * from df where XXXX="any value" AND XX > 2 ')
qual <-
sqldf('select * from df where YYYY="any value" AND XX > 2 ')
AllDataIssue <-
rbind(pros,
qual)
})
output$summary = renderPrint(summary(AllDataIssue()))
output$sample_table <- DT::renderDataTable({
DT::datatable(
{ AllDataIssue() },
caption = htmltools::tags$caption(
style = 'caption-side: bottom; text-align: center;',
'Table 1: ', htmltools::em('Any message.')
),
extensions = 'Buttons',
options = list(
fixedColumns = TRUE,
autoWidth = TRUE,
ordering = TRUE,
dom = 'Bftsp',
filter = 'top',
buttons = c('csv', 'excel')
))
})
AllDataIssue