我想在UI中做選擇選項,它應該自動將變量名稱從輸入數據中提取到列表中。這裏我選擇選項使用列表(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))
)
))
server.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時,獲得答案的機會會更好。 –
好的...我編輯了我的問題 – Punith