简体   繁体   English

在渲染图中运行ggplot时出现许多错误信号(通常发光)

[英]Many error signs when running ggplot in render plot (shiny in general)

Took very basic shiny scripts and were able to play around the generic data sets. 使用了非常基本的闪亮脚本,并且能够在通用数据集周围播放。 When I tried to put in my own and run ggplot, I've come across several errors. 当我尝试自己安装并运行ggplot时,遇到了一些错误。 Most recent is what appears in my main panel of shiny app and console in Rstudio ... "ggplot2 doesn't know how to deal with data of class reactive" ... In general, I stripped down my ggplot to the most basic elements and still not sure from where ggplot is calling data while in shiny. 最近出现的是我在Rstudio中闪亮的应用程序和控制台的主面板中显示的内容……“ ggplot2不知道如何处理类反应性的数据”……总的来说,我将ggplot分解为最基本的元素仍然不确定在闪亮时ggplot从哪里调用数据。 I am guessing the reactive function, but honestly, I am lost. 我正在猜测反应功能,但说实话,我迷路了。

Below are scripts 以下是脚本

_____ui.R________ _____ ui.R ________

shinyUI(pageWithSidebar(
  headerPanel('Mock Risk Scorecard'),
  sidebarPanel(
    selectInput('xcol', 'X Axis', names(RandomRiskCard)),
    selectInput('ycol', 'Y Axis', names(RandomRiskCard),
                selected=names(RandomRiskCard)[[2]]),
                 min = 1, max = 9),
  mainPanel(
    plotOutput('plot1')
  )
)
)

_____server.R____ _____ server.R ____

palette(c("#E41A1C", "#377EB8"))
shinyServer(function(input, output, session) { 
  # Combine the selected variables into a new data frame
  selectedData <- reactive({
    RandomRiskCard[, c(RandomRiskCard$xcol, RandomRiskCard$ycol)]
  }) 
  output$plot1 <- renderPlot({
    p <- ggplot(selectedData, aes(x = RandomRiskCard$xcol, y = RandomRiskCard$ycol))
  p <- p + geom_point()
  })
})

I also loaded up my data and Run Shiny in different script windows as follow 我还按照以下步骤在不同的脚本窗口中加载了数据并运行Shiny

install.packages("shiny")
library(shiny)
library(ggplot2)
runApp("U:/App-1")

as well as 以及

RandomRiskCard = read.csv("U:/App-1/RandomRiskCard.csv")

I am eventually hoping to incorporate factor function and annotate with colors like I had done with my original ggplot. 我最终希望像我原来的ggplot一样,加入因子函数并用颜色进行注释。 If it wasn't already obvious I am a newbie at this, but shiny has me completely twisted. 如果不是很明显,我是这个领域的新手,但是闪闪发亮的我已经完全扭曲了。

  1. Reactive expressions should be called in the same way as parameter-less functions, with following parentheses: ggplot(selectedData(),... 应使用与无参数函数相同的方式来调用反应性表达式,并带有以下括号: ggplot(selectedData(),...

  2. xcol and ycol should be obtained via input : xcol和ycol应该通过input获得:

    p <- ggplot(selectedData(), aes(x = input$xcol, y = input$ycol)) in output$plot , and p <- ggplot(selectedData(), aes(x = input$xcol, y = input$ycol))output$plot ,和

    RandomRiskCard[, c(input$xcol, input$ycol)] in selectedData RandomRiskCard[, c(input$xcol, input$ycol)]selectedData

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM