我正在创建一个Shiny App,它接收来自用户的特定类型的csv文件并以某种方式ggplots。我正在使用反应值,每次单击动作按钮时都会更新输入。但是,我一直在收到错误:
你能帮我理解为什么吗?我在评论中包含了eval(expr,envir,enclos)中的错误:找不到对象'Z'
Z
的可重现示例。
server.R
library(shiny)
library(data.table)
library(DT)
############################################################
# DEFINE REACTIVE VALUES
shinyServer(function(input, output,session) {
ntext <- eventReactive(input$goButton, {
#f1 = input$file1
#inFile <- f1
#if (is.null(inFile))
return(NULL)
#Z <- read.csv(inFile$datapath,sep=",")
# Name Track Position
# 1 A 0 1
# 2 G 0 1
# 3 C 0 1
# 4 T 0 1
# 5 T 0 1
# 6 T 0 1
# 7 AG 1 1
# 8 AG 1 2
# 9 GC 1 2
# 10 GC 1 3
# 11 CT 1 3
Z <- data.frame("Name"=c("A","G","C","T","T","T","AG","AG","GC","GC","CT","CT","AT","AT","CT","CT"),"Track"=c(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1),"Position"=c(1,1,1,1,1,1,1,2,2,3,3,4,9,10,12,13))
x <- length(levels(Z$Name))
x.colors <- hcl(h=seq(15,375,length=(x+1)),l=65,c=100)[1:x]
x.colors[1:4] <- c("blue","red","green","yellow")
########################################################
# RETURN REACTIVE VALUES
list(
Z = Z,
x.colors = x.colors,
)
})
output$nText <- renderText({
ntext()
})
############################################################
############################################################
output$plot1 <- renderPlot({
Z = ntext()$Z
x.colors = ntext()$x.colors
my_fill <- x.colors
ggplot(NULL) +
aes(x = Z$Track,
y = Z$Position,
fill = Z$Name,
label = Z$Name) +
geom_raster() +
scale_fill_manual(values=my_fill) +
theme(legend.position="none",axis.title.y = element_blank(),axis.title.x = element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank())
})
############################################################
})
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("BlahBlah"),
fluidRow(
column(3, wellPanel(
h4("Upload the correct files"),
fileInput('file1', 'Choose file',
accept=c('text/csv', 'text/plain','.csv')),
actionButton("goButton", "Update Plots")
)
)
),
hr(),
fluidRow(
column(width = 6,
plotOutput("plot1", height = 1000,
brush = brushOpts(
id = "plot2_brush",
resetOnNew = TRUE)
)
)
)
))