library(shiny)
library(ggplot2)
datasets <- c("economics", "faithfuld", "seals")
ui <- fluidPage(
selectInput(inputId = "dataset",
label = "Dataset",
choices = datasets),
verbatimTextOutput(outputId = "summary"),
plotOutput(outputId = "plot")
)
server <- function(input, output, session) {
dataset <- reactive({
get(x = input$dataset, pos = "package:ggplot2")
})
output$summary <- renderPrint({
summary(dataset())
})
output$plot <- renderPlot({
plot(dataset())
}, res = 96)
}
shinyApp(ui, server)
这是第五题的答案。有三个地方需要修改,一个是需要将tableOutput改为plotOutput; 一个需要将output$summmry改为output$summary, 一个需要将plot(dataset)改为plot(dataset()).