我正在尝试构建一个简单的shiny应用程序,该应用程序基于输入创建数据表并使用输出线图ggplot2.我收到以下错误:
错误:ggplot2不知道如何处理类packageIQR的数据
在这个应用程序中,用户使用滑块来定义时间段或X的长度,以及通过定义起始值和X上的值的变化来定义值的变化.图是线性线.我是新手shiny,所以如果有更好的方法来设置这个,我也希望有关设置服务器代码的最佳方法的建议,但是现在我只是得到一个错误并且没有产生任何情节.
server.R
library(shiny)
library(ggplot2)
shinyServer(function(input, output){
reactive({
data <- data.table(months = seq(1, input$months, by = 1),
value = seq(input$startingValue,
input$startingValue + input$valueChange,
length.out = input$months))
})
output$yield <- renderPlot({
p <- ggplot(data(), aes(x=months, y=value, colour=value)) +geom_line()
print(p)
})
})
Run Code Online (Sandbox Code Playgroud)
ags*_*udy 15
您只需要定义反应函数:
data <- reactive({
data.table(months = seq(1, input$months, by = 1),
value = seq(input$startingValue,
input$startingValue + input$valueChange,
length.out = input$months))
})
Run Code Online (Sandbox Code Playgroud)
请注意,您不需要定义反应函数,因为您有一个调用者.您可以将所有代码放在绘图部分中:
output$yield <- renderPlot({
data <- data.table(months = seq(1, input$months, by = 1),
value = seq(input$startingValue,
input$startingValue + input$valueChange,
length.out = input$months))
p <- ggplot(data, aes(x=months, y=value, colour=value)) +geom_line()
print(p)
})
Run Code Online (Sandbox Code Playgroud)