2016-06-27 1 views
0

첨부 된 MWE Shiny 예제에서 navbar 용 tabPanel 내에 중첩 tabsetPanel이 있습니다. TabSet 내에서 하나의 tabPanel 만 사용하여 MWE를 실행하면 Shiny가 예상대로 정확하게 작동하는 것을 확인할 수 있습니다. 그러나 두 tabPanels을 사용하여 MWE를 실행하면 각 탭의 기본 패널에 결과가 인쇄되지 않습니다.R Shiny : 중첩 tabPanels가 서로를 비활성화합니다.

왜이 문제가 발생합니까? 그리고 어떻게이 수수께끼를 해결할 수 있습니까?

library(shiny) 

ui <- shinyUI(navbarPage("tabalicious", 
        tabPanel("Nav1", value = "nav1", 
           mainPanel(h2("Hello"), 
             br(), 
             p("This is my app.") 
          ) 
        ) 
        , 
        tabPanel("Nav2", value = "nav2", 
           tabsetPanel(
           tabPanel("tabsettab1", 
             sidebarLayout(
              sidebarPanel(
              helpText("Choose your settings"), 
              selectInput("zone_type", 
                 label = "Choose a zone type to display", 
                 choices = list("Industrial", "Residential"), 
                 selected = "Industrial") 
              ), 
              mainPanel(h2("A tab for a tabSet"), 
                textOutput('zone_type') 
              ) 
             ) 
           ) 
           # Uncomment this to see the issue 
           # , 
           # tabPanel("tabsettab2", 
           #   sidebarLayout(
           #   sidebarPanel(
           #    helpText("Choose your settings"), 
           #    selectInput("zone_type", 
           #       label = "Choose a zone type to display", 
           #       choices = list("Industrial", "Residential"), 
           #       selected = "Industrial") 
           #   ), 
           #   mainPanel(h2("A tab for a tabSet"), 
           #      textOutput('zone_type') 
           #   ) 
           #   ) 
           #) 
           ) 
         ) 
) 
) 

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

    output$zone_type <- renderText({ 
    paste("You have selected", input$zone_type) 
    }) 
}) 

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

그것은 탭에 대해 아니다, 그것은 약 2'shinyUI' 처리 할 수없는'같은'zone_type' 변수를 렌더링 호출 textOutput'을합니다. 필요한 경우 서버 함수의 다른 이름으로'output $ zone_type'을 복사 할 수 있습니다. – alistaire

+0

답변으로 추가하십시오. –

답변

1

탭과 관련이 없지만 동일한 render* 기능의 결과를 출력하기 위해 여러 번 호출해야합니다. 예를 들어, (아무 탭) 단순화 된 페이지가 잘 작동하지만 당신이 복제 된 전화 주석을 제거하면, 표시 할 수 없게됩니다 zone_type :

library(shiny) 

server <- shinyServer(function(input, output) { 
    output$zone_type <- renderText({paste("You have selected", input$zone_type)}) 
}) 

ui <- shinyUI(fluidPage(
    selectInput("zone_type", 
       label = "Choose a zone type to display", 
       choices = list("Industrial", "Residential")), 
    # textOutput('zone_type'), 
    textOutput('zone_type') 
)) 

runApp(shinyApp(server = server, ui = ui)) 

당신의 shinyUI 기능은 내 한 번 shinyServer의 각 출력을 호출 할 수 있지만 당신이 다른 하나 개의 출력을 전달할 수 없습니다, 서버에 대한 작업을 복제하지 않으려면

library(shiny) 

server <- shinyServer(function(input, output) { 
    output$zone_type <- renderText({paste("You have selected", input$zone_type)}) 
    output$zone_type2 <- renderText({paste("You have selected", input$zone_type)}) 
}) 

ui <- shinyUI(fluidPage(
    selectInput("zone_type", 
       label = "Choose a zone type to display", 
       choices = list("Industrial", "Residential")), 
    textOutput('zone_type'), 
    textOutput('zone_type2') 
)) 

runApp(shinyApp(server = server, ui = ui)) 

: shinyServer 당신이 원하는만큼 입력을 호출 할 수 있습니다, 그래서 출력을 복제하는 것은 쉽다 그러나 render* 결과를 로컬 v에 저장할 수 있습니다 당신이 모두 출력으로 통과 할 수있는하는 가변 :

server <- shinyServer(function(input, output) { 
    zone <- renderText({paste("You have selected", input$zone_type)}) 
    output$zone_type <- zone 
    output$zone_type2 <- zone 
})