R闪光错误:找不到对象输入 [英] R Shiny error: object input not found
本文介绍了R闪光错误:找不到对象输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码是我的闪亮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)出错:找不到对象‘input’"
我正在尝试呈现一个简单的条形图,该条形图将在每个国家/地区的合同支出净值和绝对值之间切换,但它无法识别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))
推荐答案
问题在于GggPlot在提供的数据框上下文中计算变量,在您的案例中花费。您需要的是:
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。
这篇关于R闪光错误:找不到对象输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文