我编写了这段代码,为团队制作了Boxplot工具。当前,它始终是错误和沮丧的根源。我不知道这个问题是从哪里来的,但似乎是我制作新的data.frame的时候来的。如果有人能指出问题出在哪里以及如何解决,那将是很棒的。这是代码:
library(shiny)
All_Data <- data.frame(
Name = as.character(c("2015 Acidobacteria C1", "2015 Acidobacteria C1", "2015 Acidobacteria C1", "2015 Acidobacteria C1", "2015 Actinobacteria C1")),
Year = c(2015, 2015, 2015, 2015,2015),
Bacteria = as.factor(c("Acidobacteria", "Acidobacteria", "Acidobacteria", "Acidobacteria","Actinobacteria")),
Site = as.factor(c("C1", "C1", "C1", "C1","C1")),
Percents = as.numeric(c(5,2,3,5,5)),
stringsAsFactors = TRUE
)
ndata <-data.frame(
Name = as.character("Preset"),
Year = c("0"),
Bacteria = as.factor(c("0")),
Site = as.factor(c("0")),
Percents = as.numeric(c("0")),
stringsAsFactors = TRUE
)
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Boxplot Maker"),
# Sidebar
sidebarLayout(
sidebarPanel(
h3("Which Data Sets Would You Like to Compare?"),
selectInput("Set1", "", choices = All_Data$Name),
selectInput("Set2", "",choices = All_Data$Name),
selectInput("factor","Based on Which Factor?", choices = c("Year", "Site", "Bacteria", "Site by Year", "Bacteria by Year", "Bacteria by Site by Year")),
textInput("title", h4("Title"), value = "Enter title..."),
actionButton("Submit", "Submit")
),
# Show a chosen plot
mainPanel(
uiOutput("data"),
tableOutput("plot")
)
)
)
# Define server logic
server <- function(input, output) {
output$data <- renderUI(
conditionalPanel( condition = "input.Submit >0",
ndata <- filter(All_Data, All_Data$Name == input$Set1 | All_Data$Name == input$Set2)
))
output$plot <- renderTable(
boxplot(All_Data$Percents ~ All_Data$Year, data = All_Data, main = input$title)
)
}
# Run the application
shinyApp(ui = ui, server = server)