我开始使用Shiny软件包,我遇到了反应功能问题。 链接到csv文件 - here 反应函数在以下代码中不起作用:
library(shiny)
library(ggplot2)
library(jpeg)
library(grid)
library(DT)
ui<-shinyUI(fluidPage
(
titlePanel("Rapid Interpretation of Eye Movements"),
tags$style("body {background-color: #ffffcc;}"),
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
tags$hr(),
fluidRow(
column(width = 10, class = "well",
h4("Left plot controls right plot"),
fluidRow(
column(width = 10,plotOutput("plot", height = 500, brush = brushOpts(id = "plot_brush", resetOnNew = TRUE)))
)))
))
server<- shinyServer(function(input,output,session){
filedata <- reactive({
infile <- input$file1
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
read.csv(infile$datapath)
})
output$plot <-renderPlot({
bg <- rasterGrob(readJPEG(
paste0("C:/Users/tyaacov/Downloads/shinyProject/pics/1.jpg")), interpolate=TRUE)
fixationdata <- filedata()
df <- data.frame(fixationdata$HorzPos,
fixationdata$VertPos,
d = densCols(fixationdata$HorzPos,
fixationdata$VertPos,
colramp = colorRampPalette(rev(rainbow(10, end = 4/6)))))
ggplot(df) + annotation_custom(bg, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_point(aes(fixationdata$HorzPos,
fixationdata$VertPos, col = d), size = 1) +
scale_color_identity() + theme_bw() + scale_x_continuous(name="",limits = c(0, 920)) + theme(axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank()) + scale_y_continuous(name="",limits = c(0, 255))
})
})
shinyApp(ui=ui,server = server)
我收到有关fixationdata
未找到的错误。从单独检查事项我只能猜测这个问题的根源是反应函数。
有谁知道我哪里错了?
答案 0 :(得分:0)
library(shiny)
library(ggplot2)
library(jpeg)
library(grid)
library(DT)
ui<-shinyUI(fluidPage
(
titlePanel("Rapid Interpretation of Eye Movements"),
tags$style("body {background-color: #ffffcc;}"),
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
tags$hr(),
fluidRow(
column(width = 10, class = "well",
h4("Left plot controls right plot"),
fluidRow(
column(width = 10,plotOutput("plot", height = 500, brush = brushOpts(id = "plot_brush", resetOnNew = TRUE)))
)))
))
server<- shinyServer(function(input,output,session){
filedata <- reactive({
infile <- input$file1
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
read.csv(infile$datapath)
})
output$plot <-renderPlot({
if (is.null(input$file1)) return()
#if (input$action==0) return()
#isolate({
library(ggplot2)
fixationdata <- filedata()
df <- data.frame(fixationdata$HorzPos,
fixationdata$VertPos,
d = densCols(fixationdata$HorzPos,
fixationdata$VertPos,
colramp = colorRampPalette(rev(rainbow(10, end = 4/6)))))
ggplot(df) +
geom_point(aes(fixationdata$HorzPos,
fixationdata$VertPos, col = d), size = 1) +
scale_color_identity() + theme_bw() + scale_x_continuous(name="",limits = c(0, 920)) + theme(axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank()) + scale_y_continuous(name="",limits = c(0, 255))
#})
})
})
shinyApp(ui=ui,server = server)