[英]Save the contents of a local csv file as a vector in Shiny
I have a drop-down menu in my UI: 我的UI中有一个下拉菜单:
selectInput(inputId = "Header", label = "label",
choices = x,
selected = NULL),
I would like the variable "x" in the above example to be a character vector containing roughly 100 different options. 我希望上面示例中的变量“ x”是一个字符向量,包含大约100个不同的选项。 I have these options saved in a .csv file, but I cannot get the data in the .csv file (which I've uploaded to my directory) to save as a vector.
我将这些选项保存在.csv文件中,但是无法在.csv文件(已上传到目录)中获取数据以另存为矢量。 How should I go about saving data from local .csv files into R shiny for use as menu options?
如何将本地.csv文件中的数据保存到R Shiny中用作菜单选项? I've been trying read.csv among other functions, but no luck so far.
我一直在尝试在其他功能中使用read.csv,但到目前为止还没有运气。
Do I simply have to copy them all over manually? 我是否只需要手动复制它们? I assume there's an easier way.
我认为有一个更简单的方法。
Example data
write.table(rownames(mtcars), "mtcars.csv",
row.names = FALSE, col.names = FALSE, quote = FALSE)
library(shiny)
# User interface that lets you to select input
ui <- fluidPage(
selectInput("mySelection", "Select input", "")
)
server <- function(input, output, session) {
observe({
# Load your csv file
x <- read.csv("mtcars.csv", header = FALSE)
# Update selection mySelection (passed to UI)
updateSelectInput(session, "mySelection",
label = "Select input",
choices = x[, 1],
selected = x[, 1][1]
)
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.