【发布时间】:2020-08-31 14:08:58
【问题描述】:
我想启动一个闪亮的应用程序进行练习,用户可以从下拉列表中选择钻石数据集(来自 ggplot2)的“切割”列中的值。
我的用户界面如下:
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Reactive Boxplot"),
# Show a boxplot of the selected cut
mainPanel(
selectInput("column", label = h3("Column to plot"),
choices = c("", diamonds$cut),
selected = 1,
width='55%',
multiple = FALSE),
plotOutput("diamondshist")
)
)
)
我不知道如何将输入变量定义为钻石数据集“切割”列中的五个不同值。对此有何意见?
我的服务器文件如下所示。我想我还需要调整绘图的输入数据。
library(shiny)
library(ggplot2)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
compute_plot <- reactive({
if (input$column != ""){
ggplot(diamonds[, input$column])+
labs(title = "From diamonds dataset")+
geom_boxplot(aes(x = cut, y = price))+
scale_y_reverse()
}
})
output$diamondshist <- renderPlot({
compute_plot();
})
})
【问题讨论】: