1
我试图将我的应用中的滑动条值连接到表,从上传的文件呈现,但我无法理解如何正确执行该操作。这是怎样的代码看起来现在:将sliderValues应用于输入的文件
server.r
library(shiny)
function(input, output) {
# upload the csv file
output$contents <- renderTable({
inputFile <- input$file1
if (is.null(inputFile))
return(NULL)
read.csv(inputFile$datapath, header=input$header, sep=',',
quote="'")
})
# Create a frame with our values
sliderValues <- reactive({
# Compose data frame
data.frame(
Name = c("cost",
"range"),
Value = as.character(c(input$cost,
paste(input$range, collapse=' ')
),
stringsAsFactors=FALSE)
)
})
# Show the values
output$values <- renderTable({
sliderValues()
})
}
ui.r
library(shiny)
fluidPage(
titlePanel("Cars plot"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
helpText("Note: svc file should be separated by comas, and contain ",
"single quotes only."),
checkboxInput('header', 'Header', TRUE),
tags$hr(),
sliderInput("cost", "Max cost:",
min=0, max=1000000, value=500000, pre = "$"),
sliderInput("range", "Range of MaxSpeed:",
min = 50, max = 500, value = c(100,450))
),
mainPanel(
tableOutput('contents'),
tableOutput('values')
)
)
)
最后,我使用来测试它看起来像这样的文件:
Car, Horsepower, MaxSpeed, Cost
AlfaRomeo, 200, 300, 200000
AstonMartin, 400, 310, 300000
谢谢!正是我在找什么。我不知道“子集”,今天是我学习的第一天。 –