簡體   English   中英

如何只在Shiny中加載一次文件?

[英]How to load a file in Shiny only once?

我只是想知道如何只在server.R中運行一次read.csv? 在下面的代碼中,每次更改ui.R中的輸入時,代碼都需要幾秒鍾的時間才能運行read.csv,因此我期待在開始時僅加載一次文件,然后使用相同的文件ui.R中輸入更改時的數據。 謝謝這是我的代碼:

ui.R

shinyUI(fluidPage(
     headerPanel("myApp"),
     fluidRow(   sidebarPanel(
    selectInput("myOptions", "myOptions:",
                list("1" = "1", 
                     "2" = "2",
                     "3" = "3"))
     )),
     hr(),
     plotlyOutput("prescription"),   
     hr()   
      ))

server.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


 })


 })

使用shinyServer外部的shinyServer 這應該只在開始時加載文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM