2017-12-07 5 views
0

조건부 패널을 사용하여 Shiny 앱을 동적으로 빌드하고 있습니다. 패널이 기반으로하는 조건은 시작시 평가되지 않습니다. 패널은 기본적으로 표시되며 일부 작업 후에 만 ​​사라집니다. 조건이 충족되지 않아도 패널이 표시됩니다 (input.select1.length = 0, 1보다 작음).반짝이는 조건부 패널이 시작시 평가되지 않음

최소한의 작업 예 :

Server.R :

shinyServer(function(input, output,session){ 
    output$selectInput1 <- renderUI({ 
    selectInput(
     inputId = "select1", 
     label = "Select", 
     choices = c('1','2','3'), 
     selected = NULL, 
     multiple = TRUE 
    ) 
    }) 
}) 

UI.R : @porkchop는 지적

dashboardPage(
    title = "", 

    ## Header content + dropdownMenu 
    dashboardHeader(
    title = tags$b(""), 
    titleWidth = 250 
), 

    ## Sidebar content 
    dashboardSidebar(
    width = 250, 
    sidebarMenu(
     id = "tabs", 
     menuItem("tab1", tabName = "tab", icon = icon("table")) 
    ) 
), 

    ## Body content 
    dashboardBody(
    tabItems(
     tabItem(tabName = "tab", 
     div(
      div(
      style="float: left; padding-left: 20px; padding-right: 20px; width: 350px; background-color: #F4F4F4; height: calc(100vh - 50px) !important;", 
      uiOutput('selectInput1') 
     ), 
      div(
      conditionalPanel(
       condition = "input.select1.length > 1", 
       p('hi') 
      ) 
     ) 
     ) 
    ) 
    ) 
) 
) 
+0

오른쪽 페이지를 클릭하고 당신이'input.select1.length'을 평가할 때 불평 것을 볼 수 inspect''을 클릭합니다. 그것은 적절한 명령이 아닌 것 같습니다. 'jQuery' https://api.jquery.com/length/ –

+0

Thx @PorkChop을 사용해보십시오. 이 I로 변경됨 conditionalPanel ( 상태 = "! 대해서 typeof input.select1.length == '미정의'" conditionalPanel ( 상태 = "input.select1.length> 0" P ('안녕하세요') ) )하지만 여전히 같은 오류가 발생합니다. 두 번째를 평가하지 않으려면 첫 번째 조건은 무엇입니까? – Dendrobates

+0

다른'renderUI'를 만드는 것이 더 쉽습니다. –

답변

0

, 당신의 renderUI 기능의 상태를 만들 수 있습니다 server.R :

Server.R :

,451,515,
shinyServer(function(input, output,session){ 
    output$selectInput1 <- renderUI({ 
    selectInput(
     inputId = "select1", 
     label = "Select", 
     choices = c('1','2','3'), 
     selected = NULL, 
     multiple = TRUE 
    ) 
    }) 
    output$panel1 <- renderUI({ 
    if(!is.null(input$select1) && length(input$select1) > 0){ 
     condition1 = 'true' 
    } else { 
     condition1 = 'false' 
    } 
    conditionalPanel(
     condition1, 
     p('hi') 
    ) 
    }) 
}) 

UI.R :

dashboardPage(
    title = "", 

    ## Header content + dropdownMenu 
    dashboardHeader(
    title = tags$b(""), 
    titleWidth = 250 
), 

    ## Sidebar content 
    dashboardSidebar(
    width = 250, 
    sidebarMenu(
     id = "tabs", 
     menuItem("tab1", tabName = "tab", icon = icon("table")) 
    ) 
), 

    ## Body content 
    dashboardBody(
    tabItems(
     tabItem(tabName = "tab", 
     div(
      div(
      style="float: left; padding-left: 20px; padding-right: 20px; width: 350px; background-color: #F4F4F4; height: calc(100vh - 50px) !important;", 
      uiOutput('selectInput1') 
     ), 
      div(
      uiOutput('panel1') 
     ) 
     ) 
    ) 
    ) 
) 
)