简体   繁体   English

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

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

I'm just wondering how to run read.csv in server.R only once? 我只是想知道如何只在server.R中运行一次read.csv? In the following code, each time that I change the input in ui.R, it takes a few seconds for the code to run read.csv, therefore I'm looking forward to load the file only once at the beginning then use the same data when input in ui.R changes. 在下面的代码中,每次更改ui.R中的输入时,代码都需要几秒钟的时间才能运行read.csv,因此我期待在开始时仅加载一次文件,然后使用相同的文件ui.R中输入更改时的数据。 Thanks Here is my code: 谢谢这是我的代码:

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


 })


 })

Use the variable outside of shinyServer . 使用shinyServer外部的shinyServer This should load the file only in the beginning. 这应该只在开始时加载文件。

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

相关问题 如何仅使用一次加载文件(使用闪亮的小部件选择),但是在带有Shiny运行时的R-Markdown文档中使用多次 - How to load a file (selected with shiny widget) only once but use multiple times in R-Markdown document with Shiny runtime 如何在 ShinyApp 中只加载一次 Rdata 文件 - How to load Rdata file only once in ShinyApp 在Shiny中,我只想在UI加载期间一次updateSelectInput() - In Shiny I want to updateSelectInput() only once during UI load 在 R 闪亮的服务器端只加载一次文件 - Load files only once in R shiny server end 确保 Shiny 图形仅在 shinyMobile f7Tab 中加载一次 - Ensure Shiny graphs only load once in shinyMobile f7Tab Shiny和R:仅加载一次数据-不会在应用程序每次启动时加载,并且具有进度栏 - Shiny and R: load data only once - do not load at each start of app and have progress bar 如何在 R/Shiny 中为每个用户只显示一次(模态)弹出窗口? - How to show a (modal) popup only once per user in R/Shiny? 如何限制在R Shiny中每天一次将文件导入ShinyApp? - How to restrict, importing file to shinyApp once per day in R shiny? 从一个复选框组中获取值只有一次闪亮 - obtain the values from a checkboxgroup only once in shiny R闪亮:观察仅能执行一次 - R Shiny : Observe only works once
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM