Я настраиваю макет карты, и мне нужно сгенерировать реактив data.frame()
, без необходимости использования (write.csv2()
наших table.table()
) и (read.csv()
наших read.table()
). Я хотел бы создать пустой data.frame и добавить строки, используя actionButton
, содержащие информацию, выбранную в selectInputs
, каждая новая строка отличается от первой или нет в случае повторного выпуска строки.
library(shiny)
ui<-fluidPage(
sidebarPanel(
fluidRow(
selectInput("INPUT", label="Input:" ,choices=list("",1,2,3,4,5,6,7)),
selectInput("NINPT", label="Name:", choices=list("","Area","length","width")),
selectInput("COLOUR", label="Color:", choices=list("","black","white","red","green","blue","brown","yellow")),
actionButton("ADDIN",label="add"))),
mainPanel(fluidPage(
fluidRow(tableOutput("DF_table"),tableOutput("check")))))
server1 <- function(session,input, output) {
counter <- reactiveValues(countervalue = 0) # I tried make a reactive value, and pasted in id name for each data.frame
observeEvent(input$ADDIN,{
counter$countervalue <- counter$countervalue + 1 })
DFrame<-eventReactive(input$ADDIN,{
# in this case, after I select of the three "input" options, when clicking add,
# it should generate a data.frame. So each time I clicked it would generate a new data.frame.
# just use the "rbind.data.frame" command to join the data.frame()
eval(parse(text=paste("df",as.numeric(input$INPUT),"<-data.frame(iten=",as.numeric(input$INPUT),',color="',input$COLOUR,'",name="',input$NINPT,'")',sep="")))
eval(parse(text=paste(c("rbind.data.frame(",rep("",counter$countervalue-1)),"df",1:counter$countervalue,c(rep(",",counter$countervalue-1),")"),sep="")))
})
output$DF_table<-renderTable({DFrame()})
#output$check<-renderTable({ data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT,add=counter$countervalue)})
}
shinyApp(ui,server1)
# but it can not find the data.frame : Warning: Error in rbind.data.frame: object 'df1' not found!
#---------------------------------------------------------------------------------------
# I tried make a reactive value, and add a data.frame enpty
server2 <- function(session,input, output) {
DT<-reactiveValues(DT=NULL)
observeEvent(input$ADDIN,{
DT$DT<-data.frame(iten=NULL,cor=NULL,nome=NULL)
})
# after that, join'd a empty data.frame , and new data.frame, using "rbind.data.frame" when press "actionButton"
DFrame<-eventReactive(input$ADDIN,{
rbind.data.frame(DT$DT,data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT))
})
output$DF_table<-renderTable({DFrame()})
#output$check<-renderTable({ data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT)})
}
shinyApp(ui,server2)
#---------------------------------------------------------------------------------------
# I tried add row in data.frame empty
server3 <- function(session,input, output) {
DT<-reactiveValues(DT=NULL)
observeEvent(input$ADDIN,{
DT$DT<-data.frame(iten="",color="",name="")
})
eventReactive(input$ADDIN,{
DT$DT[as.numeric(input$INPUT),]<-data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT)
})
output$DF_table<-renderTable({DT$DT})
#output$check<-renderTable({ data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT)})
}
shinyApp(ui,server3)