Shiny dashboard. Hide checkboxes but retain their default value - r

I have a shinydashboard that I hope to use as a template across several projects. In the side panel I have filters so the user can create a subset of the data, eg gender. I wish to be able to hide certain filters on some projects but still have the output to pass to functions.
For example in ui.r I have
uiOutput("genderGroup")
which I need hiding from view in the dashboard.
In server.r I have
output$genderGroup <- renderUI({
checkboxGroupInput("genderFilter",label=h5("Filter by Gender"),
choices =c("Male"= 1, "Female"= 2),
selected =c(1, 2)
)
})
I still need to capture the output from the genderGroup checkboxes as several reactive functions require the filter as an argument. I've tried hiding the uiOutput with hidden(uiOutput("genderGroup")) in ui.r but the dashboard hangs when trying to look for the value for output$genderFilter.
Note: I'm using the dashboard as a template. I do not want to rewrite functions excluding certain filters on a project by project basis. As data across all projects will contain the same filtered fields, I just want to go in and hide those filters that the project does not need for subsetting. When hidden, the default selected values will be passed to the function.
Thanks
Andrew

Related

Shiny flexdashboard filters after data is loaded

I am creating a flexdashboard that has a sidebar with a dateRangeInput() and an actionButton(). Once the date selection has been made and the button has been clicked I am using observeEvent() to run a SQL query with the selected dates and then display a data table of the results. What I want to do is setup sidebar pickerInput() filters to filter the resulting table however since the data doesn't exist when the app loads this does not work. Is there a way to have the pickerInput() filters load after the data from the query is returned?

Is there a way to slow down the input update from a numericInput ui object

So as the title say I'm looking for a way to slow down the input update form a numericInput ui object.
As a little preface, I am developing an application where I have dynamically built numeric inputs using a map function based on a drop down choice selection of numbers 1-8. So based on how many numeric inputs the user wants to compare the server will dynamically build them. And, in order to display some descriptive statistics, I had to add a actionButton that updates tables built from reactive values.
The problem arises from when I'm looking to type values into the numeric input fields. I only have about 1 second from the initial number click to finish my typing my value until I get kicked out of the numeric input field. In order to finish the number I wish to type I have to click back into the field once or twice to finish typing out the number. Once I have the number typed, I can then hit my action button to update the tables.
How do I make the numeric input fields "sleep" until the button press pulls the values for the reactive tables. I've had to do several odd workarounds due to the nature of the dynamically built numeric inputs and reactive tables/plots. Any input is very welcome.
It's hard to help without some code...
You can do something like that:
go <- reactiveVal(FALSE)
observeEvent(input[["button"]], {
go(TRUE)
})
output[["table"]] <- renderTable({
req(go())
something using the numeric inputs...
})
Does it help?

diable reactive behavior with using selectInput() function in shiny

I'm using selectInput in shiny UI for the dropdown option list. however, this one is reactive to my output table.
Can I disable this behaviour? because the table requires several more inputs and additionally I have a run button to trigger it once everything is all set.

Assigning Shiny Input Variable to Gloval Environment/Data

I'm converting some code/script to function on a shiny server.
I need to scrape html data tables from a url, and currently, to choose the id number that changes in the url I have a function.
Get_ID<-function()[readline("Please choose a number:>>> ")}
num.id<-GET_ID()
It works quite well, it prompts to write the number in by keyboard in the console, and I can run the scrape easily for that URL identified (the value is pasted into the middle of a URL to use in further code).
I'm now trying to provide a list of numbers in a drop-down list on the ui.r file.
I have a dataframe (call it df) with these values (pre-planned url ID's)
NAME number
seta 20001
setb 20002
setc 20003
setd 20004
sete 20005
I'd like for the 'NAME' to appear in the drop-down list and the corresponding value in "number" to be used and assigned to the variable "num.id" so that the rest of the script will execute with the current value chosen by the user.
For the ui side, I have something along the lines of:
selectInput("ChooseName", "df", choices=NAME),
actionButton("submit", "SUBMIT CHOICE")
and I'm stuck on the server side. I've played a bit with creating an observer for the submit button, but I can't figure out a way to have the values exist in my global environment, specifically assigned to the value "num.id" - what I was using above. I would like the choice to be unique for every user. I.e., if User A chooses "setb", this won't disrupt User B who is viewing "setd".
For background, the url scrapes a table full of numbers, for which I manipulate and match to several dataframes and then output a final graph using ggplot2. Theoretically, you may recommend I pass the reactive input's from the drop-down list into the ggplot2 code directly, but there's a lot of reformatting that happens prior to use in the plot, so I'd like to keep the steps separated.
Thanks!

R shiny gvisTable with columns selected by user in defined order

I have an R shiny webpage where I currently use gvisTable to show a selection of columns from a data.frame. The rows are dynamically selected by the user with the sidebarPanel, but right now the columns are hard-coded inside the gvisTable call.
I would like to allow the user to dynamically select the columns from a drop-down menu (see snapshot of a similar system from a non-shiny webpage). The key feature I want is to allow resorting of the columns.
Any ideas how to pass this sorted selection of columns in shiny?
I don't mind using something else instead of gvisTable if it does the job.
EDIT: Thanks for showing a solution using the sortable answer. It works both for my old and new versions of shiny. Yet, this does not seem to remember the order upon hitting "Refresh", which would be really nice to have.
So, can it save the last chosen order as a browser cookie or a similar way? The server is authenticated, and I've been told I could put the variable order in a list with the user id as the key. An example of that would be great.
In Shiny you would have to use multiple selectInput's. However, you could install ShinySky by ZJ (https://github.com/AnalytixWare/ShinySky) and use his select2 binding which allows sorting. Alternatively, you could modify the sortable binding at https://github.com/mostly-harmless/sortable.
Edit: I don't know about cookies. I use sortable in a larger app. There I have an action button to save the order selected by the user. See Data > Transform > Reorder columns. In the app data is stored in a reactiveValue. To save 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 users selected variable ordering, and values is the reactiveValue that contains the data.
The source for the app is on Github: https://github.com/mostly-harmless/radiant
As an alternative, you could also save the order of the variables in a reactiveValue. See the Shiny documentation for details.
Edit:
In global.R define a reactiveValue:
savedOrder <- reactiveValues()
When a user changes the order (this assumes you have userid available as a variable in R):
if(!is.null(input$sortable)) {
savedOrder[[userid]] <- input$sortable
}
Also, you could pass the id-value to returnOrder in case of a refresh:
if(!is.null(savedOrder[[userid]])) {
returnOrder("sortable",savedOrder[[userid]])
} else {
returnOrder("sortable",colnames(dat))
}

Resources