I have a shiny app with a sidebarLayout. The offer selection is a checkbox group in the side panel, the highchart is in the main panel with cumulative response rates over time by different offers and finally the table with the current response rate by offer is beneath both the offer checkbox group and cumulative response rate chart.
Ideally I would like to remove the checkboxGroupInput and have the legendItemClick in the highchart take over this functionality so that when a particular offer in the legend is clicked (and no longer visible on the chart) that the corresponding row in the shiny table is also hidden or removed.
I've tried tying the legend item to the checkbox in the shiny checkboxGroupInput, which works here in this JSFiddle, but it does not work with the shiny app.
p1$plotOptions(series=list(stickyTracking=F,
events=list(legendItemClick=paste("#!function(){
if (this.visible) {
$('input[value=",'"',"'+this.name+'",'"',"]').prop('checked',false);
} else {
$('input[value=",'"',"'+this.name+'",'"',"]').prop('checked',true);
}
}!#"))))
Any way I can do this?
Once again, ideally I'd like to replace the checkboxGroupInput with the legendItemClick to update my shiny table.
Related
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?
I have an interactive notebook with a few widgets, that displays a plot (+other data) based on the information given by the widgets. The plot is only displayed if a Checkbox is checked.
Everything works well except one thing: the Checkbox has a True value by default. When loading the notebook for the first time, it appears as clicked but the plot is not displayed -- if I interact with the widgets in any other way (either by re-clicking this checkbox twice, or by modifying some of the other widgets), then the plot is displayed.
Is there a way to have the plot displayed at the beginning without waiting for the user to interact?
Start by creating your checkbox with the False value
cb = widgets.Checkbox(value=False)
Then, once you have set up your observse, in the code, change the value of the checkbox to True, and this should trigger your code.
cb.value = True
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
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.
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))
}