如何更改输入值以过滤闪亮的数据?

时间:2016-01-09 15:35:04

标签: r csv shiny

我需要详细说明我的头衔。用户上传数据,然后应通过选择按钮过滤位置。然而,选择按钮的选择是“纽约”,“华盛顿”,“洛杉矶”,但位置的名称是收缩。所以,我需要更改我的选择按钮输入,以便在我停止的地方过滤我的数据。

NO;Location
1.00;DC
2.00;DC
3.00;LA
4.00;NY
5.00;NY
6.00;LA
7.00;NY
8.00;DC
9.00;DC
10.00;NY
11.00;NY
12.00;LA
13.00;LA
14.00;DC
15.00;DC
16.00;DC
17.00;NY

updateselectinput对我没有帮助。因为它完全改变了我不想要的侧边栏中的输入。

ui.R

 library(shiny)
  shinyUI(pageWithSidebar(
  sidebarPanel( 

wellPanel(fileInput('file1', 'Choose File', accept=c('text/csv',    'text/comma-separated-values,text/plain', '.csv'), multiple = TRUE),

          selectInput(inputId = "location",label = "Choose Location",
                      choices = c('All','New York', 'Washington', 'Los Angeles'), selected = "All")
          )),
mainPanel(
          tabsetPanel( id="tabs", tabPanel("Data",value="panel1",tableOutput("filteredtable"))
                       ))    ))

server.R

library(shiny)

shinyServer(function(input, output) {
   output$filteredtable <- renderTable({
    if (is.null(input$file1))
  return(NULL)
else {
  output$filetype <- renderText({
    ifelse(input$file1$type %in% c('text/csv', 
                                   'text/comma-separated-values',
                                   'text/plain', 
                                   '.csv'), 
           '', 
           HTML('<script type="text/javascript">alert("Please upload .csv    file!");</script>'))
  })}
read.csv(input$file1$datapath, header=TRUE, sep=";",
         quote='')

`uploadedfile1` <- read.csv(input$file1$datapath, sep=";")
datafiltered <- uploadedfile1

reactive({input$location <- c('All','NY', 'DC', 'LA')}) ## THIS PART IS PROBLEM!
if (input$location != "All"){

  datafiltered <- datafiltered[datafiltered$Location == input$location,]
}
datafiltered
 })})

1 个答案:

答案 0 :(得分:2)

如果您为git crlf and mode false传递selectInput命名列表,它将显示名称但返回值。在这种情况下,

choices

如果用户选择“华盛顿”,则server.R中的# ui.R library(shiny) shinyUI(pageWithSidebar( sidebarPanel( wellPanel(fileInput('file1', 'Choose File', accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv'), multiple = TRUE), selectInput(inputId = "location",label = "Choose Location", choices = ('All' = 'All', 'New York' = 'NY', 'Washington' = 'DC', 'Los Angeles' = 'LA'), selected = "All") )), mainPanel( tabsetPanel( id="tabs", tabPanel("Data",value="panel1",tableOutput("filteredtable")) )) )) 将为input$location