2015-10-11 5 views
0

Я хочу предоставить inputselect «выборы» в зависимости от загруженных файлов (fileInput). В приведенном ниже примере я хочу as.list(mydata[1, 1:5]) как значения для выбора inputselect. Позже значения подмножества будут динамическими и не будут показаны здесь.Shiny: update selectinput при изменении inFile

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. "Choices" получает новые значения, присвоенные как только обнаруживается изменение. См. Документацию здесь: 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 
    }) 
Смежные вопросы