Wet*_*ent 21 r rstudio sendmailr shiny
我正在制作一个应用程序,询问用户一些基本的调查问题.完成后,要求他们通过滑动条提供数字输入,按继续,然后生成绘图,再次询问用户输入,更新绘图等.第一个输入应该是绘图上的y1,第二个输入应该是输入应该是图上的y2,等等.但另外我想保存用户输入的数据,这样我就可以在全局的R脚本中访问它,所以可以使用sendmailR将它发送给我,这样它就可以作为文本文件下载到我的计算机上.但我无法弄清楚如何做到这一点.这是我到目前为止所拥有的.
n=10 #number of times to ask the user for input which will be stored in harv[i]
Time = seq(n)
harv = rep(0,n) #initializing vector for storage of user input at time 1 through n
############### define server logic
shinyServer(function(input, output){
# Compute the forumla text in a reactive expression since it is
# shared by the output$caption and output$mpgPlot expressions
for(i in Time){
# generate a plot
output$yieldplot <- renderPlot({
harv[i] = input$harvest
plot(Time, harv, type='p', ylim=c(0,1))
})
}#for
})
Run Code Online (Sandbox Code Playgroud)
这是ui.R文件
###########################################
##### User Interface ###################
###########################################
library(shiny)
#Define UI for app
shinyUI(pageWithSidebar(
#title
headerPanel("Game"),
mainPanel( selectInput("workexp", "Have you ever been employed:",
list("No"="no", "Yes" = "yes")),
sliderInput("push", "Choose a number",
min = 0, max = 1, value = 0.5, step= 0.01),
submitButton("Enter"),
plotOutput("yieldplot")
)#mainpanel
))#shinyUI
Run Code Online (Sandbox Code Playgroud)
另外我的循环尝试并反复生成绘图将无法工作,我假设我需要做一些反应,但我需要找出一种方法来绘制所有存储在harv中的用户定义条目.我查看了downloadHanlder,但是这会在用户的计算机上下载数据和图表.
Wet*_*ent 18
答案是在shinyServer函数之外定义一个变量.然后通过使用<<-而不是<-或在反应函数中进行全局赋值=.然后您可以在反应函数之外访问它.但是,您只能在应用程序运行时访问它,但这不是用于通过电子邮件发送输入或将输入写入文本文件的问题.