2016-08-24 2 views
0

다른 데이터 세트가 들어있는 두 개의 테이블이 있습니다. 테이블을 별도의 탭에 표시하려고합니다. 내 코드는 하나의 테이블 만 표시 할 때 완벽하게 작동하지만 두 테이블을 모두 표시하려고 할 때마다 더 이상 값이 표시되지 않고 다양한 제목이 표시됩니다. 어떤 도움이라도 대단히 감사합니다. 아래는 제 코드입니다. 라만 데이터베이스와 DT 패키지를 사용합니다.탭에 테이블 표시

server.R :

library(shiny) 
library(ggplot2) 


# Define a server for the Shiny app 
shinyServer(function(input, output) { 

# Filter data based on selections 
output$table <- DT::renderDataTable(DT::datatable({ 
data <- Pitching 
if (input$yearID != "All") { 
    data <- data[data$yearID == input$yearID,] 
} 
if (input$lgID != "All") { 
    data <- data[data$lgID == input$lgID,] 
} 
if (input$teamID != "All") { 
    data <- data[data$teamID == input$teamID,] 
} 
data 
})) 

output$table2 <- DT::renderDataTable(DT::datatable({ 
data <- Batting 
if (input$yearID != "All") { 
    data <- data[data$yearID == input$yearID,] 
} 
if (input$lgID != "All") { 
    data <- data[data$lgID == input$lgID,] 
} 
if (input$teamID != "All") { 
    data <- data[data$teamID == input$teamID,] 
} 
data 
})) 


}) 

ui.R :

library(shiny) 

# Load the ggplot2 package which provides 
# the 'mpg' dataset. 
library(ggplot2) 

# Define the overall UI 
shinyUI(
    fluidPage(
    titlePanel("Pitching"), 

    # Create a new Row in the UI for selectInputs 
    fluidRow(
    column(4, 
     selectInput("yearID", 
        "Year:", 
        c("All", 
         unique(as.integer(Pitching$yearID)))) 
), 
    column(4, 
     selectInput("lgID", 
        "League:", 
        c("All", 
         unique(as.character(Pitching$lgID)))) 
), 
    column(4, 
     selectInput("teamID", 
        "Team:", 
        c("All", 
         unique(as.character(Pitching$teamID))))) 
), 

# Create a new row for the table. 
fluidRow(
    DT::dataTableOutput("table") 

), 

fluidPage(
    titlePanel("Batting"), 

    # Create a new Row in the UI for selectInputs 
    fluidRow(
    column(4, 
      selectInput("yearID", 
         "Year:", 
         c("All", 
         unique(as.integer(Batting$yearID)))) 
    ), 
    column(4, 
      selectInput("lgID", 
         "League:", 
         c("All", 
         unique(as.character(Batting$lgID)))) 
    ), 
    column(4, 
      selectInput("teamID", 
         "Team:", 
         c("All", 
         unique(as.character(Batting$teamID))))) 
), 

    # Create a new row for the table. 
    fluidRow(
    DT::dataTableOutput("table2") 

), 

    mainPanel(
    tabsetPanel(type = "tabs", 
    tabPanel("Pitching",tableOutput("table")), 
    tabPanel("Batting", tableOutput("table2")) 
) 
) 
) 
)) 

답변

0

이 tableOutput 다시는 DT : dataTableOutput()에 두 번 (한 테이블을 호출하는 것 같아, 그리고 ()). 테이블 이름 (table 및 table2)에는 유효한 HTML 구문에서 한 번만 호출 할 수있는 ID가 제공됩니다. 당신은 두 번 전화하고 있습니다, 그래서 당신의 테이블이 나타나지 않는 이유가 될 수도 있습니다. 왜 두 번 전화해야합니까?

0

Bogdan이 언급 한 것처럼 UI에서 두 번 테이블을 렌더링하려고합니다. 이것은 귀하의 주요 문제로 보입니다.

당신이 가장 많이 쓰지만 두 번 테이블을 두 번 호출하면 두 번째 테이블에 pitching이 있고 다른 테이블에 batting이 있어야한다고 생각합니다.

아래의 업데이트 ui.R 파일 참조 :

library(shiny) 

# Load the ggplot2 package which provides 
# the 'mpg' dataset. 
library(ggplot2) 


# Define the overall UI 
shinyUI(
    fluidPage(
    mainPanel(
     tabsetPanel(type = "tabs", 
        tabPanel("Pitching", 
    titlePanel("Pitching"), 

    # Create a new Row in the UI for selectInputs 
    fluidRow(
     column(4,selectInput("yearID","Year:", 
         c("All", unique(as.integer(Pitching$yearID)))) 
    ), 
     column(4,selectInput("lgID","League:", 
         c("All",unique(as.character(Pitching$lgID)))) 
    ), 
     column(4,selectInput("teamID","Team:", 
         c("All",unique(as.character(Pitching$teamID))))) 
    ), 

    # Create a new row for the table. 
    fluidRow(
     DT::dataTableOutput("table") 

    )), 
    tabPanel("Batting", 
     titlePanel("Batting"), 

     # Create a new Row in the UI for selectInputs 
     fluidRow(
     column(4,selectInput("yearID","Year:", 
          c("All",unique(as.integer(Batting$yearID)))) 
     ), 
     column(4,selectInput("lgID","League:", 
          c("All",unique(as.character(Batting$lgID)))) 
     ), 
     column(4,selectInput("teamID","Team:", 
          c("All",unique(as.character(Batting$teamID))))) 
    ), 

     # Create a new row for the table. 
     fluidRow(
     DT::dataTableOutput("table2") 
    ) 
    ) 
    ) 
)))