【发布时间】:2018-06-09 03:52:47
【问题描述】:
我正在尝试构建一个简单的应用程序,该应用程序根据其他输入过滤的子集绘制所选变量的直方图。我在hist(dataX()$datasetInput()) 行中得到错误,它应该返回dataX$mpg。我该如何解决?
完整代码:
library(shiny)
u <- shinyUI(pageWithSidebar(
headerPanel("Staz w bezrobociu"),
sidebarPanel(
selectInput("variable", "Variable:",
list("Milles/gallon",
"Horse power")
),
textInput("nc","Number of cylinders",value = 6)
),
mainPanel(
plotOutput("Plot")
)
))
s <- shinyServer(function(input, output)
{
dataX <- reactive({mtcars[mtcars$cyl==input$nc,,drop = FALSE]})
datasetInput <- reactive({
switch(input$variable,
"Milles/gallon" = mpg,
"Horse power" = hp)
})
output$Plot <- renderPlot({
hist(dataX()$datasetInput())
})
})
shinyApp(u,s)
【问题讨论】: