所以我在R shinyApp中创建了这个功能,其中加载了一个大型数据帧
可重复示例:
大数据帧
name start end party
1 Eisenhower 1953-01-20 1961-01-20 Republican
2 Kennedy 1961-01-20 1963-11-22 Democratic
3 Johnson 1963-11-22 1969-01-20 Democratic
4 Nixon 1969-01-20 1974-08-09 Republican
5 Ford 1974-08-09 1977-01-20 Republican
6 Carter 1977-01-20 1981-01-20 Democratic
7 Reagan 1981-01-20 1989-01-20 Republican
8 Bush 1989-01-20 1993-01-20 Republican
9 Clinton 1993-01-20 2001-01-20 Democratic
10 Bush 2001-01-20 2009-01-20 Republican
11 Obama 2009-01-20 2017-01-20 Democratic
`
并提示用户上传文件。
用户输入文件:
state name party
Illinois Obama Democratic
Texas Bush Republican
Arkansas Clinton Democratic
我想访问上传文件的特定列(在本例中为' name')并使用它来对我的较大数据框进行子集化,并将较小的数据框作为数据显示给用户表
结果数据框:
name start end party
9 Clinton 1993-01-20 2001-01-20 Democratic
10 Bush 2001-01-20 2009-01-20 Republican
11 Obama 2009-01-20 2017-01-20 Democratic
到目前为止,我只有选择用户输入和显示原始数据表的代码:
UI:
ui = fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
accept=c("text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
tags$hr(),
checkboxInput("header","Header",TRUE),
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
','),
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"')
),
mainPanel(
tableOutput("contents")
)
)
)
服务器:
output$contents <- renderTable({
inFile <- input$file1
if (is.null(inFile)) return(NULL)
data = read.csv(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote)})
presReact <- reactive({
return(prestable)})
output$prestable = renderDataTable({
DT::prestable(presidentData())})