如何使用闪亮的输入/输出读取向量?

如何解决如何使用闪亮的输入/输出读取向量?

我正在使用线性回归制作一个闪亮的应用程序。我的输入/输出函数有问题,所以我使用 SelectInput 因为我想让用户可以选择 de variable 进行比较。但问题是输入/输出不采用来自 csv 文件的值。我该如何解决

代码是:

datos <- read.csv("C:/Users/jerez/OneDrive/Escritorio/UAL/Datos1.csv",sep=";",header = TRUE,stringsAsFactors = FALSE)

ui <- fluidPage(
  headerPanel("Analisis de Regresion"),sidebarPanel(
    #Eleccion de variable x
    p("Selecciona la primera variable a comparar"),selectInput(inputId = "varX",label = "Variable eje X",multiple = FALSE,choices = list("NumBusquedas","FrecuenciaAsistente","FrecuenciasCorreos","NumMensajes","Freqdiscover","NumUsosApp","Numpublicidad","NumSuscripciones","NumBusquedasYoutube")),#Eleccion de variable y
    p("Selecciona la segunda variable a comparar"),selectInput(inputId = "vary",label = "Variable eje Y","NumBusquedasYoutube"))
  ),mainPanel(
    #verbatimtextoutput(outputId = "Datos"),verbatimtextoutput(outputId = "X"),verbatimtextoutput(outputId = "Y"),verbatimtextoutput(outputId = "coefCorr"),plotOutput(outputId = "Grafico")
    
   
    
  )
)

server <- function(input,output) {
  
  output$coefCorr <- renderPrint(cor(input$varX,input$vary))
  output$Grafico <- renderPlot(ggplot(datos,aes(input$varX,input$vary)))
  output$X <- renderPrint({input$varX})
  output$Y <- renderPrint({input$vary})
  
}
# Run the application 
shinyApp(ui = ui,server = server)

结果如下: result

谢谢! :)

解决方法

两个问题:

  1. aws ec2 terminate-instances 变量是 input$*,而不是您认为的数字。使用 character

  2. 类似 datos[[input$*]];指定美学的首选程序化方式是通过 ggplot 代替。 (我之前建议首选 .data[[ input$* ]],现在是 deprecated。感谢 @starja 帮助我看到这一点。)

如何解决 下次进入此绑定时:将 aes_string 插入到导致问题的块的开头的某处。 (另一种方法是使用我在此答案底部包含的技术。)现在,我会选择:

browser()

(由于我没有您的数据,我将从 output$coefCorr <- renderPrint({ browser() cor(input$varX,input$var) }) 开始,并将两个选择输入更改为 datos <- mtcars。)

当您运行该应用程序时,它应立即进入控制台上的调试器,等待执行下一行代码 (choices=names(datos))。幸运的是,我们在一个 cor(...) 中,它将 sink(.) 所有的输出。虽然这是设计使然,但在我们停止 renderPrinting 之前,我们将在控制台上实现零交互。为此,sink 停止它。

sink(NULL)

在两个字符串上运行 sink(NULL) input$varX # [1] "mpg" input$varY # [1] "mpg" cor("mpg","mpg") # Error in cor("mpg","mpg") : 'x' must be numeric 关系有意义吗?您可能需要的是 cor:

datos[[input$varX]]

当然这是完美的“1”,这次都是同一个变量。为了演示,我将退出调试器,将 Y 变量更改为 cor(datos[[input$varX]],datos[[input$varY]]) # [1] 1 ,然后重新进入调试器:

"disp"

这解决了 cor(datos[[input$varX]],datos[[input$varY]]) # [1] -0.8475514 错误。

但是,一旦您到了尝试绘图的地步,您就会发现您遇到了另一个问题。 (我将继续使用 numeric 内的当前调试器,只是因为它很方便。)我将添加 renderPrint 以便显示一些内容。

geom_point()

ggplot,single categorical point

这只是一点。两个轴都是具有值 ggplot(datos,aes(input$varX,input$varY)) + geom_point() "mpg" 的分类变量。在这种情况下,我们用 "disp" 对抗 ggplot2 的非标准评估。相反,告诉 ggplot 你给它strings,用

aes()

ggplot,fixed

最重要的是,这两个服务器块应该是这样的:

ggplot(datos,aes(.data[[ input$varX ]],.data[[ input$varY ]])) + geom_point()

(我仍在推断 output$coefCorr <- renderPrint({ cor(datos[[input$varX]],datos[[input$varY]]) }) output$Grafico <- renderPlot(ggplot(datos,.data[[ input$varY ]])) + geom_point()) ,不过这只是为了演示。)


附注:在学习和开发闪亮的应用程序时,我经常插入一个按钮和 geom_point 只是为了让我直接访问,而不是在 observe 块中。例如,

render

当您遇到问题并且不想停止闪亮的应用程序只是为了插入 ui <- fluidPage( headerPanel("Analisis de Regresion"),sidebarPanel( actionButton("debug","DEBUG!"),# ... ),mainPanel( # ... ) ) server <- function(input,output) { observeEvent(input$debug,{ req(input$debug); browser(); 1; }) # ... } 并重新运行它时,只需按下按钮。

(这不应该部署到闪亮的服务器,它只与本地模式相关。事实上,我相信尝试使用 browser() 部署应用程序应该触发警告,如果不是更多。无论哪种方式,不要尝试使用远程服务器上的调试按钮:-)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?