You can do that by using updateTextInput().
Here's the help on that function.
Here's what the updated server.R will look like:
Modified Server.R
Note that two lines have been added to the alterdata() reactive function.
library(shiny)
library(plyr)
shinyServer(function(input,output,session){
dataset = reactive({
inFile<-input$file
if(is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header=input$header, sep=input$sep)
})
alterdata = reactive({
if(input$addcol!=0&&input$addvar!=0){
isolate({
df<-dataset()
df$Var1<-eval(parse(text=input$newformula), df)
df<-rename(df, c(Var1=input$newvar))
#add these two lines
updateTextInput(session, "newvar", value = " ")
updateTextInput(session, "newformula", value = " ")
df
})
}
else
{
dataset()
}
})
output$contents<-renderTable({
if (is.null(input$file)) { return() }
alterdata()
})
})
Note that I had to include plyr
so that rename
could be invoked.