eval(expr, envir, enclos) 错误:找不到对象 'input'
Error in eval(expr, envir, enclos) : object 'input' not found
我试图让用户select他们想要绘制哪一列数据(selecty)。除了这一部分,我的应用程序中的其他所有内容都有效。以下是我的代码的相关部分:
#ui.R
library(shiny)
library(ggplot2)
shinyUI(fluidPage(h1("Title 1"),
# Sidebar
sidebarLayout(
sidebarPanel(
h3("Title 2"),
selectInput("pnum",
label = "Select the patient number",
choices = unique(pnums), selected = pnums[1]),
selectInput("selecty",
label = "Choose a variable to display on the y-axis",
choices = list('Var1', 'Var2', 'Var3', 'Var4')),
dateRangeInput("dates", label= "Date Range"),
submitButton("Create Graph")
),
# Show a plot
mainPanel(
plotOutput('makeplot')
)
)
))
#server.R
#relevant portion only - ggplot
library(shiny)
require(RODBC)
library(ggplot2)
library(quantmod)
library(reshape)
shinyServer(function(input, output) {
output$makeplot <- renderPlot({
p <- ggplot(pdata(), aes(x = Time_Stamp, y = input$yselect)) + geom_point()
print(p)
})
})
数据来自在线数据库,是一个反应函数。我的主要问题是,在列的用户 select 中,它必须用单引号引起来,尽管我想将它转移到不带引号的 ggplot 函数,因此它充当列名。我也尝试在 'y = ' 中创建一个 switch 语句,但我得到了同样的错误。
首先,在你的 ggplot 调用中,你应该 y = input$selecty
与你在 ui.R
中的命名保持一致。
那么,如果我没理解错的话,你应该看看ggplot
中的aes_string
函数,因为aes
使用了非标准的评估,它允许你直接指定变量名而不是作为字符。此处,input$yselect
作为字符传递,因此您需要在 server.R
中替换:
p <- ggplot(pdata(), aes(x = Time_Stamp, y = input$yselect)) + geom_point()
与
p <- ggplot(pdata(), aes_string(x = "Time_Stamp", y = input$selecty)) + geom_point()
我试图让用户select他们想要绘制哪一列数据(selecty)。除了这一部分,我的应用程序中的其他所有内容都有效。以下是我的代码的相关部分:
#ui.R
library(shiny)
library(ggplot2)
shinyUI(fluidPage(h1("Title 1"),
# Sidebar
sidebarLayout(
sidebarPanel(
h3("Title 2"),
selectInput("pnum",
label = "Select the patient number",
choices = unique(pnums), selected = pnums[1]),
selectInput("selecty",
label = "Choose a variable to display on the y-axis",
choices = list('Var1', 'Var2', 'Var3', 'Var4')),
dateRangeInput("dates", label= "Date Range"),
submitButton("Create Graph")
),
# Show a plot
mainPanel(
plotOutput('makeplot')
)
)
))
#server.R
#relevant portion only - ggplot
library(shiny)
require(RODBC)
library(ggplot2)
library(quantmod)
library(reshape)
shinyServer(function(input, output) {
output$makeplot <- renderPlot({
p <- ggplot(pdata(), aes(x = Time_Stamp, y = input$yselect)) + geom_point()
print(p)
})
})
数据来自在线数据库,是一个反应函数。我的主要问题是,在列的用户 select 中,它必须用单引号引起来,尽管我想将它转移到不带引号的 ggplot 函数,因此它充当列名。我也尝试在 'y = ' 中创建一个 switch 语句,但我得到了同样的错误。
首先,在你的 ggplot 调用中,你应该 y = input$selecty
与你在 ui.R
中的命名保持一致。
那么,如果我没理解错的话,你应该看看ggplot
中的aes_string
函数,因为aes
使用了非标准的评估,它允许你直接指定变量名而不是作为字符。此处,input$yselect
作为字符传递,因此您需要在 server.R
中替换:
p <- ggplot(pdata(), aes(x = Time_Stamp, y = input$yselect)) + geom_point()
与
p <- ggplot(pdata(), aes_string(x = "Time_Stamp", y = input$selecty)) + geom_point()