【发布时间】:2023-03-23 17:50:01
【问题描述】:
嘿,我有一个闪亮的应用程序,它输入数据并与它们一起工作。但现在我想要一个动作按钮,它为子集功能选择因子。问题是当我启动应用程序并输入数据时,因素不存在,在第一次点击操作按钮后,因素得到数据的列名。
如何进行编程,以便在读取数据后直接向我显示因子。感谢您的帮助!
这里是 UI 和服务器的一部分
radioButtons(
"fileType_Input",
label = h5("Choose file type and click on browse"),
choices = list(".csv" = 1, ".xlsx" = 2),
selected = 1,
inline = TRUE
),
fileInput('file1', '' ),
selectInput("letters", label=NULL, factors, multiple = TRUE),
actionButton("choose", "Auswahl"),
verbatimTextOutput("list")
服务器:
shinyServer(function(input, output, session) {
# Get the upload file
myData <- reactive({
inFile <- input$file1
if (is.null(inFile)) {
return(NULL) }
if (input$fileType_Input == "1") {
read.csv2(inFile$datapath,
header = TRUE,
stringsAsFactors = FALSE)
} else {
read_excel(inFile$datapath)
}
})
# When the Choose button is clicked, add the current letters to v$choices
# and update the selector
observeEvent(input$choose, {
data <- myData()
factors <- colnames(data) # get the names of the Factors in a Vector to select them
v$choices <- input$letters # append(v$choices,input$letters)
updateSelectInput(session, "letters",
choices = factors #[!factors %in% v$choices)]
)
})
output$list <- renderPrint({
v$choices
})
【问题讨论】:
标签: r shiny shiny-server