【发布时间】:2016-01-09 15:35:03
【问题描述】:
我需要详细说明我的标题。用户上传数据,然后应通过选择按钮过滤位置。但是,selectbutton 的选择是“New York”、“Washington”、“Los Angeles”,但是位置的名称是缩写。所以,我需要更改我的选择按钮输入,以便在我停止的地方过滤我的数据。
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"))
)) ))
服务器.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
})})
【问题讨论】: