本文介绍了在渲染图中运行ggplot时出现许多错误标志(一般闪亮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 采用了非常基本的闪亮脚本,并能够玩弄通用数据集。当我试图放入我自己并运行ggplot时,我遇到了几个错误。最近的是什么出现在我的主要面板闪亮的应用程序和控制台在Rstudio ... ggplot2不知道如何处理类反应数据 ... 一般情况下,我将ggplot分解为最基本的元素,但仍然不确定ggplot在哪里调用数据。我猜测反应函数,但老实说,我迷路了。 以下是脚本 _____ 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 ____ palette(c(#E41A1C, #377EB8)) shinyServer(函数(输入,输出,会话){#将选定的变量组合到一个新的数据框中 selectedData RandomRiskCard [,c(RandomRiskCard $ xcol,RandomRiskCard $ ycol)] }) output $ plot1 p p< - p + geom_point()})}) 我的数据和运行Shiny在不同的脚本窗口如下 install.packages(shiny) library(闪亮)库(ggplot2) runApp(U:/ App-1) 以及 RandomRiskCard = read.csv(U:/App-1/RandomRiskCard.csv) 我最终希望合并因子函数并用颜色标注颜色,就像我对原始ggplot所做的那样。如果它还不是很明显,我是一个新手,但闪亮的是我完全扭曲。 解决方案 反应式表达式应该和无参数函数一样调用,用下面的括号: ggplot(selectedData(),... 通过输入: p 在输出$ plot 和 selectedData 中的RandomRiskCard [,c(输入$ xcol,输入$ ycol)] / li> 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. 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. I am guessing the reactive function, but honestly, I am lost. Below are scripts _____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____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 followinstall.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. If it wasn't already obvious I am a newbie at this, but shiny has me completely twisted. 解决方案 Reactive expressions should be called in the same way as parameter-less functions, with following parentheses: ggplot(selectedData(),...xcol and ycol should be obtained via input:p <- ggplot(selectedData(), aes(x = input$xcol, y = input$ycol)) in output$plot, andRandomRiskCard[, c(input$xcol, input$ycol)] in selectedData 这篇关于在渲染图中运行ggplot时出现许多错误标志(一般闪亮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-10 07:42