2017-07-14 5 views
2

renderUIを使用するモジュール化された光沢のあるコードのMWEを提供できますか?私はそれに従う例が欲しい。これを光沢のあるモジュールに変換するには

ここでは、これについて説明する優れたチュートリアルがあります。https://shiny.rstudio.com/articles/modules.htmlしかし、uUIやサーバーでのrenderUIコンポーネントのモジュール化を統合する方法は示されていません。ここで

は、私がこれまで試したものです:

私のUIコードでは、私が持っていた:私のサーバーコードで

htmlOutput("selectionUI") 

を、私が持っていた:今

output$selectionUI <- renderUI({ 
    req(input$Filter) 
    selectInput(
     inputId = "Selection", 
     label = "Selection", 
     choices = get("qlist", envir = get(input$source))[[input$Filter]]$responses) 
    }) 

私は希望これは時には繰り返される要素なので、モジュール化するのが好きですが、いったん完了したら、それを実際にui/serverコードに挿入する方法がわかりません。ここで

は、私が試したものです:

selectionChooserUI <- function(id) { 
    ns <- NS(id) 
    uiOutput(ns('controls')) 
} 

selectionChooser <- function(input, output, session, data, sourcedata, filter) { 
    output$selectionUI <- renderUI({ 
    req(input$Filter) 
    ns <- session$ns 
    selectInput(
     inputId = ns('Selection'), 
     label = 'Selection', 
     choices = get('qlist', envir = get(input[[sourcedata()]]))[[input[[filter()]]]]$responses 
    ) 
    }) 
} 

私はそれは、現在私が取得しています苦情"output" is missing with no defaultことをdiplayしてもらうために、私のUIコードに入れなければならないのですか?

私が使用して、私のUIコードで、現在それを呼んでいる:

selectionChooserUI("selection") 
+0

あなたは 'selectionChooserUI'であなたの' output'を 'controls'と名づけました。あなたはあなたのデータを持っていないのでテストしていません。ですから、 'selectionChooser'で' $ control'を出力する必要があります。 – user5029763

+0

そして、あなたは 'input $ Filter'と' input [[filter()]]の代わりに 'filter()'を使うべきだと思います。 – user5029763

+0

ありがとう@ user5029763私はこれらの変更を加え、同じエラーが発生しました。 'エラー:引数 'output'がデフォルトなしで欠落しています。 ' –

答えて

2

それはおそらくこのようなものです。

library(shiny) 

ui <- fluidPage(
    h1("Get me a Module!"), 
    selectInput("source", "Some source", choices = letters[1:4]), 
    selectInput("filter", "Some filter", choices = letters[1:4]), 
    selectionChooserUI("id_of_me") 
) 

server <- function(input, output, session) { 
    get_me_choices <- reactive({ 
    get("qlist", envir = get(req(input$source)))[[req(input$filter)]]$responses }) 

    callModule(module = selectionChooser, id = "id_of_me", choices = get_me_choices) 
} 

selectionChooserUI <- function(id) { 
    ns <- NS(id) 
    uiOutput(ns('selection')) 
} 

selectionChooser <- function(input, output, session, choices) { 
    ns <- session$ns 

    output$selection <- renderUI({ 
    selectInput(
     inputId = ns('selection'), 
     label = 'Selection', 
     choices = choices 
    ) 
    }) 
} 
+0

これはアプリのモジュール化に役立ちましたか? – user5029763