So I am creating this feature in R shinyApp where a load a
large dataframe
Reproducible Example:
Large dataframe
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
`
and prompt the user to upload a file.
user Input file:
state
name party
Illinois Obama Democratic
Texas Bush
Republican
Arkansas Clinton
Democratic
I would like to access a
particular column of the uploaded file (in this case 'name') and use it to subset my
larger data frame and display the smaller data frame back to the user as a data
table.
Resulting Data
Frame:
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
So far I have only the
code for selecting user input and displaying the original data table:
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")
)
)
)
server:
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())})
No comments:
Post a Comment