2017-09-27 17 views
0

おそらく変化するcsvファイルのリストからレンダリングされる選択入力オプションを表示する必要があります。光沢のあるUI:CSVファイルの長いリストからSelect Inputの名前を表示する - 表示方法?

ユーザは最初に、ラジオボタンを使用して、彼が検査したい詳細ビューを選択します。ここでは、選択した選択肢にパスを追加するだけで、正しいフォルダに移動します。 2番目のステップでは、ユーザーは「フルーツ」詳細ビューを選択できる必要があります。したがって、私はgsubでCSVファイルの巨大なリストをフィルタリングし、これは正常に動作しますが、名前はselect入力フィールドに表示されず、さらにエラーメッセージが表示されます。

それをより簡単にするために、コード:

ui.R

 tabItem(tabName = "mainTab", 

    # control boxes   

    fluidRow(
     box(
     title = "Please select a fruit representation", 
     width = 12, 
     status = "info", 
     color = "maroon", 
     collapsible = FALSE, 
     radioButtons(
      inputId = "fruit_view", 
      label = "", 
      choices = c("Top Fruit View", 
      "Current Fruit Split", 
      "Top Fruit & Value Class"), 
      selected = "Top Fruit View", 
      inline = TRUE) 
    ) 
    ), 
    fluidRow(

     box(
     title = "Selected Fruit:", 
     width = 4, 
     collapsible = FALSE, 
     selectInput(
     inputId = "fruit_selection", 
     label = "", 
     choices = "") 

server.R

get_fruitView <- reactive({ 
    switch(input$fruit_view, 
    "Top Fruit View" = dir(
     path = "data/fruits/", full.names = TRUE), 
    "Current Fruit Split" = dir(
     path = "data/splits/", full.names = TRUE), 
    "Top Fruit & Value Class" = dir 
    (path = "data/classes/", full.names = TRUE)) 
}) 


# loading the modeled data by fruit 

     visible_fruits <- reactive({ 

     fruit_choiced <- get(input$fruit_view) 

     fruit_choice <- view_choiced()[c(gsub(view_choiced(), 
     pattern = "[^_]+_[^_]+_([^_]+)_[^_]+", replacement = "\\1"))] 

     basename(unique(fruit_choice)) 
    }) 

    observe({ 
     updateSelectInput(session, "", 
     choices = visible_fruits()) 
    }) 

正規表現が正常に動作し、私がしたい名前を隔離表示されますが、ユーザー入力には表示されません。

ありがとうございます。

ところで私は、このエラーメッセージが表示されます。ここでは

Warning: Error in serverFuncSource: server.R returned an object of unexpected type: environment 
Stack trace (innermost first): 
    1: shiny::runApp 
Error in serverFuncSource() : 
    server.R returned an object of unexpected type: environment 
Warning: Error in get: object 'input' not found 
Stack trace (innermost first): 
    58: get 
    57: <reactive:visible_channels> [C:\Users\m.nierhoff\Desktop\AnalyseR\RAnalysen\channel-forecasting/server.R#60] 
    46: visible_channels 
    45: updateSelectInput 
    44: observerFunc [C:\Users\m.nierhoff\Desktop\AnalyseR\RAnalysen\channel-forecasting/server.R#69] 
    1: shiny::runApp 
+0

にあなたがそれをやりたいしませんが、それが見える場合、私に教えてください'updateIelect'変数を' updateSelectInput'に入れていないので、 'shiny'は更新する' selectInput'を知りません。 –

+0

'' '$ fruit_view''を入力して' '' 'を' '使っても動作しません。 '' 'view_choiced()' 'はどこにありますか? – amrrs

答えて

0

は、動的に入力オプションを変更する別の方法です。私は手動で2.csv1.csvと呼ばれる3つのCSVを作成している

library(shiny) 

ui <- fluidPage(

    # Application title 
    titlePanel("Select CSV demo"), 

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
     sidebarPanel(
     radioButtons(
      inputId = "fruit_view", 
      label = "Select a fruit", 
      choices = c("Top Fruit View"="1", 
         "Current Fruit Split"="2", 
         "Top Fruit & Value Class"="3"), 
      selected = "1", 
      inline = TRUE) 
    ), 

     # Show a plot of the generated distribution 
     mainPanel(

     uiOutput("ChoicesUI") 
    ) 
    ) 
) 


server <- function(input, output) { 

    output$ChoicesUI <- renderUI({ 
    a <- read.table(paste0(input$fruit_view,".csv")) 
    selectInput("Choices2", 
       label="select from file", 
       choices = a$V1) 
    }) 
} 

# Run the application 
shinyApp(ui = ui, server = server) 

、および:ここで私は私のserver.RにUI要素を作成するために、uiOutputrenderUI機能のペアを使用して、この利点はserver.Rが任意のRのコードを実行することができるということです3.csvには、それぞれの行に3つの異なる要素があり、この作業を行います。

enter image description here

あなたはさらに説明する必要があるか、これは私がデータを持っていないとして、私は私のコメントを確認することはできません

+0

あなたの入力@ michael-birdに感謝します。あなたの例は正常に動作しますが、私の問題ではうまくいかないようです。問題をより明確にするために私の質問を編集します。 – MHN