2017-01-01 113 views
1

這裏是我的代碼:[R閃亮 - 一個tabpanel和輸出

shinyServer <- function(input, output) { 

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

    } 

shinyUI <- fluidPage(
    titlePanel("censusVis"), 
    fluidRow(
    column(3, textInput('text_input', label = 'some label', value ='')), 
    column(9, 
      tabsetPanel(
       tabPanel('result', 
          fluidRow(
          column(12, h3('Test_header'), 
            textOutput('text_out') 
          ) 
         ) 
       ), 
       tabPanel('some panel', tableOutput('table')), 
       tabPanel('another panel', tableOutput('table')) 

     ) 
    ) 
) 

) 
shinyApp(ui=shinyUI, server = shinyServer) 

它的工作原理,但它並沒有顯示線"You have selected",如果我評論在代碼tabPanel('another panel', tableOutput('table'))以下行,然後行"You have selected"顯示出來。你知道什麼是錯的,爲什麼tabPanel影響輸出?

回答

3

在兩個tabPanel中使用兩次相同的輸出tableOutput('table')。這就是爲什麼它沒有顯示text_out。使用此 -

shinyServer <- function(input, output) { 

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

} 

shinyUI <- fluidPage(
    titlePanel("censusVis"), 
    fluidRow(
     column(width = 3, textInput('text_input', label = 'some label', value ='')), 
     column(width = 9, 
       tabsetPanel(
        tabPanel(title = 'result', 
          fluidRow(
           column(width = 12, 
             h3('Test_header'), 
             textOutput('text_out') 
           ) 
          ) 
        ), 
        tabPanel(title = 'some panel', 
          tableOutput('table1') 
        ), 
        tabPanel(title = 'another panel', 
          tableOutput('table2') 
        ) 
       ) 
     ) 
    ) 
) 
shinyApp(ui=shinyUI, server = shinyServer)