Здесь я добавляю новый столбец в свой фрейм данных.
Приведенный ниже код работает хорошо. После добавления нового столбца тексты внутри «Имя переменной» и «Формула» должны быть пустыми.Очистить ввод текста после отправки
Не могли бы вы помочь мне.
ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("", ""),
sidebarPanel(
wellPanel(
fileInput('file', 'Select csv file', accept=c('text/csv')),
checkboxInput('header', 'Header', TRUE),
gsub("label class=\"radio\"", "label class=\"radio inline\"",
radioButtons('sep', 'Separator', c(Comma=',', Semicolon=';', Tab='\t')))
),
wellPanel(
checkboxInput('addcol', 'Create New Variable', FALSE),
conditionalPanel(condition="input.addcol!=0",
textInput('newvar', "Variable name",""),
textInput('newformula', "Formula",""),
actionButton("addvar","Apply"))
)
),
mainPanel(
tabsetPanel(
tabPanel(tableOutput('contents'))
)
)
))
server.R
library(shiny)
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))
df
})
}
else
{
dataset()
}
})
output$contents<-renderTable({
if (is.null(input$file)) { return() }
alterdata()
})
})
Спасибо ... Это сработало. Вы добавили реактивную функцию clearText, я думаю, что это не требуется. А также я добавил reshape вместо plyr, он работает .. – Punith