Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何将文件只加载一次?_R_Shiny - Fatal编程技术网

R 如何将文件只加载一次?

R 如何将文件只加载一次?,r,shiny,R,Shiny,我只是想知道如何在server.R中只运行一次read.csv?在下面的代码中,每次我更改ui.R中的输入时,代码运行read.csv都需要几秒钟,因此我希望在开始时只加载一次文件,然后在ui.R中的输入更改时使用相同的数据。谢谢 这是我的密码: 用户界面 服务器.R library(utils) library(plotly) library(plyr) shinyServer(function(input, output) { diseases<-eventReactive

我只是想知道如何在server.R中只运行一次read.csv?在下面的代码中,每次我更改ui.R中的输入时,代码运行read.csv都需要几秒钟,因此我希望在开始时只加载一次文件,然后在ui.R中的输入更改时使用相同的数据。谢谢 这是我的密码:

用户界面

服务器.R

library(utils)
library(plotly)
library(plyr)


shinyServer(function(input, output) {


  diseases<-eventReactive({
    diseases=read.csv("diseases_94.csv",header=F)
 })


  output$prescription <- renderPlotly( {

   myDiseases=diseases
   freq=count(myDiseases,"DISEASES")

   p<-plot_ly(freq, labels = ~DISEASES, values = ~freq, type = 'pie',
        textposition = 'inside',
        textinfo = 'label+percent',
        insidetextfont = list(color = '#FFFFFF'),
        hoverinfo = 'text',
        text = ~paste(DISEASES),
        marker = list(line = list(color = '#FFFFFF', width = 1)))



 p


 })


 })
库(utils)
图书馆(绘本)
图书馆(plyr)
shinyServer(功能(输入、输出){

使用
shinyServer
外部的变量。这应该只在开始时加载文件。

如果您只想加载一次,为什么可以在服务器功能外部加载它?也许您可以告诉我们更多您希望何时以及如何读取数据,@BigDataScientist感谢您的响应。我只需要在b处加载当我运行shiny应用程序时开始运行。然后我应该将其作为输入参数传递给shinyServer函数吗?你可以像使用普通变量一样使用它,…@BigDataScientist获得了它!它正在工作。非常感谢
library(utils)
library(plotly)
library(plyr)


shinyServer(function(input, output) {


  diseases<-eventReactive({
    diseases=read.csv("diseases_94.csv",header=F)
 })


  output$prescription <- renderPlotly( {

   myDiseases=diseases
   freq=count(myDiseases,"DISEASES")

   p<-plot_ly(freq, labels = ~DISEASES, values = ~freq, type = 'pie',
        textposition = 'inside',
        textinfo = 'label+percent',
        insidetextfont = list(color = '#FFFFFF'),
        hoverinfo = 'text',
        text = ~paste(DISEASES),
        marker = list(line = list(color = '#FFFFFF', width = 1)))



 p


 })


 })