2015-10-11 111 views
0

我想提供inputselect依賴上傳的文件(fileInput)的「選擇」。在下面的示例中,我想要as.list(mydata[1, 1:5])作爲輸入選擇選項的值。稍後,子集值將是動態的,不會在此顯示。閃亮:更新inFile的更改selectinput

enter image description here

我試圖在論壇提出了若干方案(反應,觀察,reactiveValue及其組合),但沒有成功。

我的腳本部分運行,但是我需要刷新頁面以獲取上傳的「選項」並重新加載文件。

server.R

shinyServer(function(input, output, session) { 

output$contents <- renderDataTable({ 

    inFile <<- input$SoftRecom 
    if (is.null(inFile)) 
     return(NULL) 
    filedatapath <<- reactive({inFile$datapath}) 
    mydata <<- read.csv(filedatapath(), header = TRUE, sep = ',') 
    mydata 
}) 


mychoices <<- reactive({ 
    mydata 
    print(mydata) 
    }) 

output$vg <- renderUI({ 
    selectInput("vg", label = p("goal", style = "color:#FFA500"), 
     mychoices()[1,1:5], selected = 1) 
}) 

output$vp <- renderUI({ 
    selectInput("procedure", label = p("procedure", style = "color:#FFA500"), 
       choices = c("proecudures"), selected = 1) 

}) 

output$vm <- renderUI({ 
    selectInput("procedure", label = p("procedure", style = "color:#FFA500"), 
       choices = c("ChIP-seq"), selected = 1) 

}) 
}) 

ui.R

shinyUI(fluidPage(theme = "bootstrap.css", 
titlePanel("simple software recommendation sytem"), 
sidebarLayout(
    sidebarPanel(
     fileInput('SoftRecom', 'choose dataset'), 

     uiOutput("vg"), # variable goal 
     uiOutput("vp"), # variable procedure 
     uiOutput("vm") # variable method 


    ), 
    mainPanel(
     dataTableOutput('contents') 
    ) 
) 
)) 

我見過很多例子,在論壇的答案,非常接近(甚至匹配),我的問題。對不起,因爲太鈍了。如果有人能指出我的問題,我會非常感激。

Jay

回答

0

最終我自己找到了解決方案。不要因爲我的問題和答案中的不同服務器代碼而感到困惑。只要看看

  • uiOutput( 'pipelinestep')和
  • 輸出$ pconst < <之間的關係 - renderUI({selectizeInput( 'pconst', '構建軟件的工作流程',選擇= as.character( mysoft [mysoft $目標== mypipefilter,3]), 多個= TRUE,選項=名單(maxItems = 1))}

UI.R

我不得不插入:uiOutput(「pipelinestep 「)看到一行8

shinyUI(fluidPage(theme = "bootstrap.css", 
titlePanel(h2("simple software recommendation system", style = "color:#FFA500")), 
    sidebarLayout(position = "left", 
     sidebarPanel(width =3, 
      # chose standard pipeline 
      selectInput("selectpipe", "select standard pipeline:", choices = pipechoices), 
      # software details 
      *uiOutput("pipelinestep")*, # software per pipeline step, 
      # construct software workflow based on selected pipeline step 
      uiOutput("pconst") 
     )))) 

server.R

看到從管線5〜7「的選擇」,即會檢測到改變分配新值。請參閱文檔:http://shiny.rstudio.com/articles/dynamic-ui.html

pipelinestepsoftInput <<- reactive({ 
    mypipefilter <- input$pipelinestep 
    softperpipe <<- mysoft[mysoft$goal==mypipefilter ,c(1,3,5:7), drop = FALSE] 
    ## provides software choices related to the pipeline step 
    output$pconst <<- renderUI({selectizeInput(
     'pconst', 'construct software workflow', choices = as.character(mysoft[mysoft$goal==mypipefilter, 3]), 
     multiple = TRUE, options = list(maxItems = 1))}) 
    ## input for outputDataTable 
    softperpipe 
    })