R闪亮错误:找不到对象输入

用户名

以下代码是我的Shiny ui:

library(shiny)
shinyUI(fluidPage(

titlePanel("All Country Spend"),

  sidebarLayout(
    sidebarPanel(  selectInput("split", 
        label = "Choose Fill For the Chart",
        choices = c("Action.Obligation","Action_Absolute_Value"),
      selected = "Action.Obligation"
        )
            ),
    mainPanel(plotOutput("SpendChart"))
)
))

以下是服务器代码:

library(shiny)
library(ggplot2)

shinyServer(function(input, output) {

spend <- read.csv("data/Ctrdata.csv")
output$SpendChart <- renderPlot({

    Country <- spend$Principal.Place.of.Performance.Country.Name
    ggplot(spend, aes(x = Country, y = input$split)) + geom_bar(stat = "identity")

})

})

每次我运行它时,都会出现以下错误:

“ eval(expr,envir,enclos)中的错误:找不到对象'输入'”

我正在尝试绘制一个简单的条形图,该条形图将在每个国家/地区的合同支出的净值和绝对值之间切换,但是它无法从selectInput框中识别出我的输入“ split”

这是我的数据框示例:

data.frame(Country = c("Turk", "Turk", "Saudi", "Saudi", "Ger", "Ger"),
Action.Obligation = c(120,-345,565,-454, 343,-565),
Action_Absolute_Value = c(120,345,565,454,343,565))
康拉德

问题是与ggplot提供的数据帧的情况下评估变量,你的情况。您想要的是:

ggplot(spend, aes_string(x = "Country", y = input$split))

因此,您的工作server.R代码为:

library(shiny)
library(ggplot2)

shinyServer(function(input, output) {

spend <- data.frame(Country = c("Turk", "Turk", "Saudi", "Saudi", "Ger", "Ger"),
                    Action.Obligation = c(120,-345,565,-454, 343,-565),
                    Action_Absolute_Value = c(120,345,565,454,343,565))

    output$SpendChart <- renderPlot({


        ggplot(spend, aes_string(x = "Country", y = input$split)) +
            geom_bar(stat = "identity")

    })

})

显然,你可以更换支出与CSV导入DF。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章