我想從我上傳到應用程序的「汽車」數據集中獲取速度變量。基本上在選擇速度:我想所有的數字出現在數據集$速度。在selecInput下,選擇應該取決於我使用fileInput上傳的數據集。我怎樣才能完成這項任務。現在我已經將這些選項添加爲1,2,3。理論上應該有汽車數據集的速度變量的所有值。FileInput按鈕與selectInput閃亮..!
library(shiny)
library(datasets)
##the file I am uploading
data(cars)
dataset=write.csv(cars, "dataset.csv")
ui=fluidPage(
actionButton("upload", "Upload File"),
bsModal("uploadFile", " ", "upload",
sidebarLayout(
sidebarPanel(
fileInput("file","Choose file to upload")
),
mainPanel(
tableOutput("contents")
)
)
),
sidebarLayout(
sidebarPanel(
column(3, selectInput("selectElement", "Select speed:", c(1,2,3),multiple =
T, selectize = F)
)
),
mainPanel(
)
)
)
server=function(input,output,session){
output$contents <- renderTable({
inFile <- input$file
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath)
})
}
shinyApp(ui,server)
此代碼不起作用 – Sumeda
它適用於我。我正在使用Chrome。從sessionInfo()中提取。請檢查你是否有相同的版本(特別是有光澤)。 > sessionInfo()R 3.3.3版(2017年3月6日) (...) 其他附軟件包: [1] shiny_1.0.1 經由一個命名空間加載(和未附): [1 ] R6_2.2.0 htmltools_0.3.5 tools_3.3.3 Rcpp_0.12.10 [5] jsonlite_1.4 digest_0.6.12 xtable_1.8-2 httpuv_1.3.3 [9] mime_0.5 – Enzo