I am trying to make an app that according to the selection of the user will subsetting the dataframe of the data. After that I want to create a new dataframe with unique values of col1 abd and the new dataframes added as new columns to the existing dataframe depending on users choice (like from a long shape of the dates making them in wide). Any thoughts??? my dataset is that
col1<-rep(c(1:4),3)
col2<-c('a','b','c','a','b','c','a','b','c','a','b','c')
col3<-c(1,2,3,NA,NA,14,15,NA,NA,20,21,22)
col4<-c(NA,NA,1,2,3,14,15,20,21,22,NA,NA)
df<-data.table(col1,col2,col3,col4)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
selectInput('Ind', 'Index',choices = c(unique(df$col2))),
dataTableOutput('Table')
)
# Define server logic required to draw a histogram
server <- function(input, output) {
dfsel<-reactive({dfnew<-subset(df,col2==input$Ind)
dfnew
})
output$Table<-renderDataTable(dfsel())
}
# Run the application
shinyApp(ui = ui, server = server)
what ia am trying to achive is when first the user selects 'a'
the results to be this
col1 col2 col3 col4
1 a 1
2 a 20 22
3 a 15 15
4 a 2
Then if the user selects c the new dataframe will be
col1 col2 col3 col4 col2 col3 col4
1 a 1 c 21
2 a 20 22 c 14 14
3 a 15 15 c 3 1
4 a 2 c 22
and so on
