Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 闪亮应用程序不根据输入更改输出_R_Ggplot2_Shiny - Fatal编程技术网

R 闪亮应用程序不根据输入更改输出

R 闪亮应用程序不根据输入更改输出,r,ggplot2,shiny,R,Ggplot2,Shiny,我使用以下代码创建了一个闪亮的应用程序: library(shiny) ui <- fluidPage( selectInput("mr", label="Type of Merchandise", choices=c("Groceries", "WhiteGoods", "HomeGoods","Clothes"), selected="Groceries"), plotOutput("curv"

我使用以下代码创建了一个闪亮的应用程序:

library(shiny)
ui <- fluidPage(
  selectInput("mr",
              label="Type of Merchandise",
              choices=c("Groceries", "WhiteGoods", "HomeGoods","Clothes"),
              selected="Groceries"),
  plotOutput("curv")
)

server <- function(input, output){
  output$curv <- renderPlot({
    ggplot(new, aes(x=Year, y=Sales, colour = input$mr)) +
      geom_point(alpha=.3) +
      geom_smooth(alpha=.2, size=1) +
      ggtitle("Fitted curve for overall sales")
  })
}

shinyApp(ui = ui, server = server)

我是不是在代码中遗漏了什么?非常感谢您的帮助。

这是一个工作版本
new[new$commodies==input$mr,]
根据您的选择过滤数据。还有一些列名不匹配,我已经更改了它们

library(shiny)
library(ggplot2)

ui <- fluidPage(
    selectInput("mr",
                label="Type of Merchandise",
                choices=c("Groceries", "White goods", "Home goods","Clothes"),
                selected="Groceries"),
    plotOutput("curv")
)

server <- function(input, output){

    output$curv <- renderPlot({
        ggplot(new[new$Merchandise==input$mr,], aes(x=Year, y=Total.Sales)) +
            geom_point(alpha=.3) +
            geom_smooth(alpha=.2, size=1) +
            ggtitle("Fitted curve for overall sales")
    })
}

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(GG2)

ui您没有根据输入筛选数据,因此它总是打印所有销售数据。谢谢您的回复。在哪里添加过滤器?对不起,我是新手。谢谢你的意见。然而,我现在得到了一个空白图。有什么我应该做的吗?这里工作正常。您的数据帧是否命名为“新建”
,并且读取正确?并确保列名匹配。只需运行
new
进行检查,它就会显示其中的数据。列名也匹配。不知道为什么它仍然给我一个灰色的空白图。嗨,我再次创建了数据框,现在它工作了。非常感谢你的帮助!干杯
library(shiny)
library(ggplot2)

ui <- fluidPage(
    selectInput("mr",
                label="Type of Merchandise",
                choices=c("Groceries", "White goods", "Home goods","Clothes"),
                selected="Groceries"),
    plotOutput("curv")
)

server <- function(input, output){

    output$curv <- renderPlot({
        ggplot(new[new$Merchandise==input$mr,], aes(x=Year, y=Total.Sales)) +
            geom_point(alpha=.3) +
            geom_smooth(alpha=.2, size=1) +
            ggtitle("Fitted curve for overall sales")
    })
}

shinyApp(ui = ui, server = server)