对象“输入”未找到并对象“输出”;在 R Shiny 应用程序中找不到

发布于 2025-01-11 13:32:51 字数 1192 浏览 0 评论 0原文

我正在尝试在 R 中的 Shiny App 中创建散点图,但我不断收到无法找到我的输入和输出的错误消息。我已经尝试了所有我能想到的可能导致这些问题的方法,但到目前为止尚未解决。我真的很感激一些帮助。我的代码如下:

我的 UI:

shinyUI(fluidPage(
  titlePanel("Scatterplot Basketball Statistics"),
    sidebarPanel(
      selectInput(inputId = "x", 
                    label = "Select variable to plot",
                      choices = names(dt.basketball),
                        selected = "Season"),
      selectInput(inputId = "y",
                    label = "Select variable to plot against",
                      choices = names(dt.basketball),
                        selected = "3PA"),
  #Output: Show the output of the scatter plot
  mainPanel(
    plotOutput(outputId = "scatterplot")
))
)
)

和我的服务器:

library(ggplot2)
library(shiny)

shinyServer(function(input,output){
    output$scatterplot <- renderPlot({
    
    ggplot(data = dt.basketball, aes_string(input$x, input$y) + geom_point())
   
})
})

我收到的错误消息如下:

Error in output$scatterplot <- renderPlot({ : object 'output' not found

Error in aes_string(input$x, input$y) : object 'input' not found

I'm trying to create a scatter plot in Shiny App in R, but I keep getting the error messages that my input and output can not be found. I've tried all the things I could think of that could be causing these issues, but as of yet it is unresolved. I'd really appreciate some help. My code is the following:

My UI:

shinyUI(fluidPage(
  titlePanel("Scatterplot Basketball Statistics"),
    sidebarPanel(
      selectInput(inputId = "x", 
                    label = "Select variable to plot",
                      choices = names(dt.basketball),
                        selected = "Season"),
      selectInput(inputId = "y",
                    label = "Select variable to plot against",
                      choices = names(dt.basketball),
                        selected = "3PA"),
  #Output: Show the output of the scatter plot
  mainPanel(
    plotOutput(outputId = "scatterplot")
))
)
)

And my server:

library(ggplot2)
library(shiny)

shinyServer(function(input,output){
    output$scatterplot <- renderPlot({
    
    ggplot(data = dt.basketball, aes_string(input$x, input$y) + geom_point())
   
})
})

The error messages I get are the following:

Error in output$scatterplot <- renderPlot({ : object 'output' not found

and

Error in aes_string(input$x, input$y) : object 'input' not found

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文