【发布时间】:2013-09-01 11:29:16
【问题描述】:
我正在尝试在 ui 中选择选项,它应该自动将变量名称从输入数据中提取到列表中。这里我在选择选项中使用了 list(ls(input.file1),但它不起作用。
请帮帮我。
ui.R:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel( "Demand Forecast", "Flowserve"),
sidebarPanel(
fileInput('file1', 'Select csv file',
accept=c('text/csv')
),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
c(Comma=',', Semicolon=';', Tab='\t')
),
tags$hr(),
selectInput("product", "Select Product",
list(ls(input.file1))
)
))
服务器.R:
library(shiny)
shinyServer(function(input,output){
#Assigning data to a variable "data1"
data1 = reactive({
inFile<-input$file1
if(is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header=input$header, sep=input$sep)
})
sub=reactive({
subset(data1(), select=paste0(input$product))
})
output$contents<-renderTable({
if (is.null(input$file1)) { return() }
sub()
})
})
这是 csv 示例:
Product1 Product2 Product3
5 10 17
8 16 26
10 20 32
16 32 50
18 36 56
20 40 62
【问题讨论】:
-
提供简短的 csv 样本时,获得答案的机会会更大。
-
好的...我已经编辑了我的问题