![](/img/trans.png)
[英]How to load a file (selected with shiny widget) only once but use multiple times in R-Markdown document with Shiny runtime
[英]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.