我有两个包含不同数据集的表。我希望这些表格在单独的选项卡上显示。我的代码完美地工作,当我只显示一个表,但每当我尝试显示两个表的值不再显示,只是各种标题。任何帮助深表感谢。以下是我的代码。我使用拉曼数据库和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"))
)
)
)
))