2017-06-14 7 views
0

私は、ユーザーがあらかじめ提供されたリストから1つまたは複数の関数(モジュール)を選択できるようにするアプリケーションを構築しようとしています。その選択に基づいて、関数。R光沢のあるレンダリングUIウィジェット対話的に

基本的には、renderUI呼び出しツリーを再構築しようとしています。その結果、光沢のある反応部分が発生し、サーバー関数が呼び出されると、$ abcd.in入力がNULLでない場合、renderUI関数は、引数は入力$ abcd.inの値に依存します。

エラーは、set_output_automatically関数の入力引数の長さが0であると思われますが、次に何をすべきかわかりません。

は、ここで私はdo.callcallを置き換え簡略化した例

library(shiny) 

arg.info <- list(
    list(choices = c("Yes" = T, "No" = F), 
        prompt = quote(paste("Remove Missing Values for analysis?")), 
        type = "radioButtons"), 
    list(choices = c("not" = 0, "some" = 1, "very" = 3), 
     prompt = quote(paste("how cool are you?")), 
     type = "checkboxGroupInput")) 


set_output_automatically <- function(input, arg.info){ 

    if(input[1] > 3){ 
    arg.info <- arg.info[[1]] 
    } else { 
    arg.info <- arg.info[[2]] 
    } 

    renderUI({ 

    call(arg.info$type, paste0(input$abcd, ".in"), label = arg.info$prompt, 
     choices = arg.info$choices) 
    }) 


} 

ui <- fluidPage(

    uiOutput('abcd'), 

    textOutput('value'), 

    uiOutput('result') 


) 

server <- function(input, output){ 

    output$abcd <- renderUI({ 

    checkboxGroupInput('abcd.in', 'sample', 
         choices = c('wowe'= 1, 
            'such' = 2, 
            'choice' = 3, 
            'very' = 4, 
            'programe' = 5)) 

    }) 

    output$value <- renderPrint({input$abcd.in}) 

    output$result <- reactive(set_output_automatically(input$abcd.in, arg.info)) 

} 

shinyApp(ui, server) 

答えて

0

(引数リストを持つ)とrenderUIと反応性である、これは動作します。

library(shiny) 

arg.info <- list(
    list(choices = c("Yes" = T, "No" = F), 
     prompt = quote(paste("Remove Missing Values for analysis?")), 
     type = "radioButtons"), 
    list(choices = c("not" = 0, "some" = 1, "very" = 3), 
     prompt = quote(paste("how cool are you?")), 
     type = "checkboxGroupInput")) 


set_output_automatically <- function(input, arg.info){ 
    if(input[1] > 3){ 
    arg.info <- arg.info[[1]] 
    } else { 
    arg.info <- arg.info[[2]] 
    } 
    do.call(arg.info$type, args=list(inputId=paste0("in", input), label = arg.info$prompt, 
      choices = arg.info$choices)) 

} 

ui <- fluidPage(
    uiOutput('abcd'), 
    textOutput('value'), 
    uiOutput('result') 
) 

server <- function(input, output){ 

    output$abcd <- renderUI({ 
    checkboxGroupInput('abcd.in', 'sample', 
         choices = c('wowe'= 1, 
            'such' = 2, 
            'choice' = 3, 
            'very' = 4, 
            'programe' = 5)) 
    }) 

    output$value <- renderPrint({input$abcd.in}) 

    output$result <- renderUI({ 
    set_output_automatically(input$abcd.in, arg.info) 
    }) 

} 

enter image description here

+0

ありがとう!!コールとdo.callの違いは何ですか? do.callは呼び出しを作成して評価しますが、呼び出しは単に呼び出しを作成する場所です。 – HuntAC

+0

呼び出しは関数呼び出しを返しますが、評価しません(したがって、do.callの "do"は同じですが評価されるため)。 '' do.call( "mean"、list(5,6)) 'は5.5を返しますが、' call( "mean"、5,6) 'はmeanと5と6の評価されていない呼び出しを与えます。 6) ':) – shosaco

+0

追加:' eval'を使って呼び出しを評価することができます: 'myCall < - call(" mean "、c(5,6)); eval(myCall) 'は' 5.5'を返す – shosaco

関連する問題