2017-11-06 22 views
0

私はチェックボックスから複数のものを選択できる光沢のあるアプリを作成しようとしています。入力に基づいて、関連するすべてのテキスト出力フィールドを返す必要があります。これを行うにはチェックボックスから複数の入力が返され、複数のテキスト出力が返される

、私は、チェックボックスをインデックスし、if文で複数の条件を使用しますが、input1を選択したときに何かが動作しませんよ。私はinput2input1の両方を選択した場合、それはただの結果を示しinput2; input1を選択すると、光沢のあるアプリがクラッシュします。

私はチェックするために条件を追加しようとしましたが、運はありません。以下

コード:

library(shiny) 
library(shinydashboard) 


ui <- shinyUI(

    navbarPage("DBC Comparison", 
      tabPanel("Stats" , 
         sidebarLayout(
         sidebarPanel(

          checkboxGroupInput("comp_type", "Comparison type", choices = c("input1", "input2", "input3")), 

          actionButton(
          inputId = "submit_loc", 
          label = "Submit") 
          , width = 3), 

         mainPanel(

          fluidRow(
          column(6, textOutput("selected_var1")), 
          #DT::dataTableOutput("table")#, 
          # div(style = 'overflow-x: scroll', tableOutput('table')) 
          column(6,textOutput("selected_var2")) 
         ), position="left")) 
) 
)) 

## 


## 
server <- shinyServer(function(input, output) { 
    observeEvent(
    eventExpr = input$submit_loc, 
    handlerExpr = 
    { 
     if(input$comp_type[1] == 'input2' || input$comp_type[2] == 'input2' || (input$comp_type[1] == 'input1' & input$comp_type[2] == 'input2')) 
     { 
     output$selected_var2 <- renderText({ 
      "2" 
     })} 
     else if(input$comp_type[1] == 'input1' ||input$comp_type[2] == 'input1'||input$comp_type[3] == 'input1'|| (input$comp_type[1] == 'input1' & input$comp_type[2] == 'input2') 
                      || (input$comp_type[2] == 'input1' & input$comp_type[1] == 'input2') 
     { 
     output$selected_var1 <- renderText({ 
      "1" 
     }) 
     } 



    })  




}) 
## 
shinyApp(ui = ui, server = server) 

任意のアイデア?

答えて

2

input$comp_type[2] == 'something'は、少なくとも2つのアイテムを選択していない場合はNAを生成します。したがって、ifステートメントはエラーを返します。

また、私は観察でレンダリングを使用しないでください。
あなたの例を変更して、より簡単なeventReactiveを使用します。

あなたの条件について何も得られなかったので、私はちょうどランダムなものを書きました私はそれにどう対処するか見てみましょう。

library(shiny) 
library(shinydashboard) 


ui <- shinyUI(

    navbarPage("DBC Comparison", 
      tabPanel("Stats" , 
         sidebarLayout(
         sidebarPanel(

          checkboxGroupInput("comp_type", "Comparison type", choices = c("input1", "input2", "input3")), 

          actionButton(
          inputId = "submit_loc", 
          label = "Submit") 
          , width = 3), 

         mainPanel(

          fluidRow(
          column(6, textOutput("selected_var")) 
          #DT::dataTableOutput("table")#, 
          # div(style = 'overflow-x: scroll', tableOutput('table')) 
         ), position="left")) 
      ) 
)) 

## 


## 
server <- shinyServer(function(input, output) { 

    toDisplay <- eventReactive(input$submit_loc, { 
    if (all(c("input1", "input2", "input3") %in% input$comp_type)) { 
     return("all input selected") 
    } else if (all(c("input2", "input3") %in% input$comp_type)) { 
     return("input2 and input3 selected") 
    } else if ("input1" %in% input$comp_type) { 
     return("At least input1 is selected") 
    } else { 
     return("you are not in a random case I wrote") 
    } 
    }) 
    output$selected_var <- renderText({ 
    toDisplay() 
    }) 

}) 
    ## 
    shinyApp(ui = ui, server = server) 
+0

これは私が探していたものですが、if文では%in%を使用していましたが、 – Barbara

関連する問題