R brilliant gvisTable with columns selected by the user in a specific order

I have an R shiny webpage where I am currently using gvisTable to display a selection of columns from data.frame. Rows are dynamically selected by the user using the sidebarPanel , but right now the columns are hardcoded inside the gvisTable call.

I would like to allow the user to dynamically select columns from the drop-down menu (see a snapshot of such a system from a non-shiny web page). The key function I want is to allow the use of columns.

enter image description here

Any ideas how to convey this sorted list of columns in brilliant form?

I don't mind using something else instead of gvisTable if it does the job.

EDIT: Thanks for showing the solution using a sortable answer. It works for both my old and new shiny versions. However, this does not seem to remember the order when clicking “Refresh”, which would be very nice to have.

So, can it save the last selected order as a browser cookie or similar? The server is authenticated, and I was told that I can put the variable order in a list with the user ID as the key. An example of this would be great.

+6
source share
1 answer

In Shiny, you have to use multiple selectInput. However, you can install ShinySky by ZJ ( https://github.com/AnalytixWare/ShinySky ) and use its select2 binding, which allows you to sort. Alternatively, you can change the sortable binding at https://github.com/mostly-harmless/sortable .

Edit: I do not know about cookies. I am using sortable in a larger application . There I have an action button to save the order selected by the user. See Data> Transform> Reorder. In the application, data is stored in activeiveValue. To preserve the data order, I use values[[input$datasets]] <- values[[input$datasets]][,input$tr_reorder_cols] , where input$datasets is the active dataset, input$tr_reorder_cols is the user-selected ordering order , and values is a react valid containing data.

The source of the application is Github: https://github.com/mostly-harmless/radiant

Alternatively, you can also save the order of the variables in the reactiveValue file. See the Shiny documentation for more details.

Edit:

In global.R, define the reactive valid:

 savedOrder <- reactiveValues() 

When the user reorders (assuming you have a user ID available as a variable in R):

 if(!is.null(input$sortable)) { savedOrder[[userid]] <- input$sortable } 

In addition, you can pass the id value of returnOrder in case of an update:

 if(!is.null(savedOrder[[userid]])) { returnOrder("sortable",savedOrder[[userid]]) } else { returnOrder("sortable",colnames(dat)) } 
+5
source

All Articles