Shiny FileInput按钮,选择Input in闪亮。。!
我试图从我上传到应用程序的汽车数据集中获取速度变量。基本上在selectspeed下:我希望所有的数字都出现在dataset$speed中。在selecInput下,选择应该取决于我使用fileInput上传的数据集。我怎样才能完成这项任务。现在我已经添加了选项1,2,3。从理论上讲,应该有汽车数据集的所有速度变量值Shiny FileInput按钮,选择Input in闪亮。。!,shiny,rstudio,Shiny,Rstudio,我试图从我上传到应用程序的汽车数据集中获取速度变量。基本上在selectspeed下:我希望所有的数字都出现在dataset$speed中。在selecInput下,选择应该取决于我使用fileInput上传的数据集。我怎样才能完成这项任务。现在我已经添加了选项1,2,3。从理论上讲,应该有汽车数据集的所有速度变量值 library(shiny) library(datasets) ##the file I am uploading data(cars) dataset=write.csv(c
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)
我为一个有点不完整的回答提前道歉:见下文 首先,回答您的问题: 如果您有一个类似cars的数据集,要识别速度标签,可以执行以下操作:
labls <- unique(cars$speed)
...
selectInput("selectElement", "Select speed:", labls, multiple =
T, selectize = F)
我希望发布一个完整的示例,但当前的逻辑可能是因为发布的代码有限?似乎不对:应用程序a如何留给用户选择使用哪个文件;同时b已经过滤了速度?
当然,您可能计划显示所有列均为“速度”的数据集,这样才有意义:
此外,但这不是你问题的一部分,你似乎通过shinyBS包使用了模态对话
由于2016年10月左右的Shinny版本0.14有一个非常好的模态函数,我个人认为最好使用本机函数
我想发布一个简单的示例,它源于您的代码,但selectInput for speed被注释掉了,因为如前所述,它在发布的示例上下文中并不正确
library(shiny)
library(datasets)
data(cars)
dataset = write.csv(cars, "dataset.csv")
labls <- unique(cars$speed) # I left this in the code
ui=fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("upload", "Upload File")
),
mainPanel(tableOutput("contents") )
))
server=function(input,output,session){
# Show modal when button is clicked.
observeEvent(input$upload, {
showModal(dataModal())
})
dataModal <- function(failed = FALSE) {
modalDialog(
fileInput('inputId', label=NULL, multiple = FALSE, accept = NULL, width = NULL, buttonLabel = "Browse...", placeholder = "No file selected")
# , selectInput("selectElement", "Select speed:", labls, multiple =
# T, selectize = F)
)
}
output$contents <- renderTable({
if (length(input$inputId )== 0) return(NULL)
inFile <- input$inputId
# if (is.null(input$selectElement )) return(NULL)
input$inputId
})
}
shinyApp(ui,server)
它对我有用。我用的是Chrome。摘自sessionInfo。请检查您是否有相同的版本,尤其是闪亮版本。>2017-03-06版本3.3.3的会话。。。其他附加软件包:[1]Shining_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