2
여기에서 데이터 프레임에 새 열을 추가하고 있습니다.
아래 코드가 잘 작동합니다. 새 열을 추가 한 후 "변수 이름"및 "수식"안의 텍스트는 비어 있어야합니다.제출 후 일반 텍스트 입력
도와주세요.
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 리 액션 기능을 추가했는데 필요하지 않다고 생각합니다. 그리고 또한 plyr 대신 재구성을 추가했는데 작동 중입니다. – Punith