Shiny 用于选择输入的闪亮文件输入

Shiny 用于选择输入的闪亮文件输入,shiny,Shiny,我试图在UI中通过selectInput下拉菜单访问colnames(input$file1)。此外,我希望选择的默认列作为第一个数字列。我不知道该怎么做。这超出了我的能力范围。如果有人有任何建议,我将非常感谢 谢谢, 格温 runApp( 名单( ui=fluidPage( titlePanel(“使用readxl”), 选项卡面板( 选项卡面板(“上传数据”, 侧栏面板( helpText(“在此处输入excel文件。我们假定数据位于 第一行为页眉的第一张图纸。“), br(), 文件输入(

我试图在UI中通过selectInput下拉菜单访问colnames(input$file1)。此外,我希望选择的默认列作为第一个数字列。我不知道该怎么做。这超出了我的能力范围。如果有人有任何建议,我将非常感谢

谢谢, 格温

runApp(
名单(
ui=fluidPage(
titlePanel(“使用readxl”),
选项卡面板(
选项卡面板(“上传数据”,
侧栏面板(
helpText(“在此处输入excel文件。我们假定数据位于
第一行为页眉的第一张图纸。“),
br(),
文件输入(“文件1”,“选择Excel文件”,
接受=c(
“xls”,
“xlsx”)
),
br()
)),
##这就是我完全迷路的地方。
选项卡面板(“一般输入”,
选择输入(“选择”,标签=h3(“选择列”),
choices=colnames(M()[[1]]),selected=M()[[2]][1])
)
),
服务器=功能(输入、输出){
M=无功({
M=标记列表()

我把它修好了!这管用
 runApp(
 list(
   ui = fluidPage(
    titlePanel("Use readxl"),
  tabsetPanel(
    tabPanel("Upload Data",
             sidebarPanel(
               helpText("Input an excel file here. We assume the data are in the 
                        first sheet with the first row being headers."),
               br(),

               fileInput("file1", "Choose Excel File",
                         accept = c(
                           "xls",
                           "xlsx")
               ),
               br(),

               actionButton("UI", "Add my data")
             )),

    tabPanel("General Inputs",
             uiOutput("VarsInput")
    )

  )),

server = function(input, output){
  M = reactive({
    inFile <- input$file1
    M = tagList()

    if(is.null(inFile))
      return(NULL)
    file.rename(inFile$datapath,
                paste(inFile$datapath, ".xlsx", sep=""))
    D = read_excel(paste(inFile$datapath, ".xlsx", sep=""), 1)
    D = as.data.frame(D)

    ## Upating file names
    colnames(D) <- labs <- gsub("\r\n"," ", colnames(D))
    nums = labs[which(sapply(D, is.numeric) == TRUE)]

    M[[1]] = D
    M[[2]] = nums

    M
  })

  output$VarsInput <- renderUI({
    selectInput("Choose a variable", "Variable to randomize:",
                choices = colnames(M()[[1]]), selected = M()[[2]][1])
  })

  }
 )
 )