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