-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reset value of actionButton? #167
Comments
No, not at this time. Can you talk a little about why you want this? Thanks... |
i was trying to bypass the issue with the radiobuttons(and the updateradiobuttons).so here is the logic. We have 2 buttons lets say b1 and b2. when a button is pushed then it is increased by 1 in server.R we render some text for this action.after it, the button must reseted to 0 so that if the state of a button is 1 it must trigger some text rendering and etc. but i think you gave me the answer. but it would be a nice addition for some ui control enhancement.what's your opinion? |
Don't think of the value of the input$actionButtonId as being meaningful, except for the special case of 0, which means "the button hasn't been pressed yet". In all other cases, you should just rely on the fact that input$actionButtonId changes and invalidates your reactive expression or observer. If you find yourself checking the actual value of input$actionButtonId (other than testing for 0) then it's a good sign you probably need to look again at using
|
Actually I think the reset is useful. I have an app that contains multiple projects. E.g. each project could be a different data set I am analysing, so when I switch projects I would want to reset all buttons as if they have never been pressed. |
I have the exact same problem where resetting the actionbuttons would help alot. An user is able to switch locations / working directories where he can analyse & create plots for different data sets. For all these different data sets the same plot buttons are being used. As soon as you would change the working directory now all scripts get called because buttons have been pressed already. |
I'm facing this issue too. I have two buttons add and clear to build a query. when i select something and say add, that term should be added to query and if click on clear button, it should clear the query. i'm checking for add_button>0 now but that won't really solve my purpose because when i select something else after clicking add button it'll automatically be added to the query. i tried resetting the actionbutton value but really could not. |
i did an odd workaround instead, using a var which i reset to 0 as soon as the button is pressed. I'm using input$h5fileName so the user can load another file. observe ({
input$h5fileName
counter_createTime_Plot <<- 0
}) when call the function i want to run i increment this ensuring its run every time i actually press the actionButton. observe({
# increment the counter so i know it has been pressed
if (counter_createTime_Plot == 0)
counter_createTime_Plot <<- counter_createTime_Plot + 1
#returning when the ui.R is opened the first time
if (input$createTime_Plot == 0)
return()
# run the function because the button is clicked once after loading a new file
else if (counter_createTime_Plot == 1) {
}) I use the counter value 1 to do a check if the file is correct, using a next if statement with if (counter_createTime_Plot > 1) to use the same actionButton for doing something else. It's not a pretty solution but for now it works the way i want it to. Being able to reset would still be much better. |
I still don't think you need this. If your add logic is surrounded by isolate you shouldn't have this problem. If I'm wrong, let me know. |
in sarvagna's case most likely yes, since i suspect his input field is in the same observer as both actionButtons (maybe share the code?). In my case however i have a button which has to check the data input when it is clicked the first time, when clicking it for the second time it should not check the datainput but create a plot instead. A third click would do nothing since the data is validated and the plot has been made. The user is also able to switch files however and as soon as he/she does the plot button became useless. In this situation it would be perfect if i could just reset the actionbutton instead when a a different file is loaded. Now i have to keep track how many times it is clicked with an external counter variable. |
Here is my code, i tried to use the logic you mentioned. this works well first time i click either add or clear button. but after that the buttons are useless. observe({
if (input$add_button == 0)
return()
isolate({
selected_term_ids<-c(input$thti,input$select_child_terms)
if((!is.null(selected_term_ids)) & length(selected_term_ids)>0){
onto <- input$search_option
selected_terms <- get_onto_terms_by_ids(paste0(selected_term_ids,collapse=","))
}
if(!is.null(DisplayString$names)){
DisplayString$names<-unique(append(DisplayString$names,selected_terms$term))
QueryString$names<-unique(append(QueryString$names,selected_term_ids))
}
else{
DisplayString$names<-selected_terms$term
QueryString$names<-selected_term_ids
}
output$dynamic_value <- renderText({
paste0(DisplayString$names, collapse=",")
})
})
if(input$clear_button == 0)
return()
isolate({
DisplayString$names<- NULL
QueryString$names <- NULL
output$dynamic_value <- renderText({DisplayString$names})
})
}) |
Try using two observers, one for each button. Also, what are DisplayString and QueryString? Just normal lists or reactiveValues objects? |
they are reactiveValues objects. I'll be using the displaystring in verbatimtextoutput and querystring in db query function further down the code |
In that case output$dynamic_value only needs to be assigned once, outside of any observer. |
Well i did something like this and it seems to be working for now.
|
I really wish one could reset an actionButton to 0. |
@sharko666 Let me know if you have a simple example of why you need that. I'm totally open to being convinced but haven't seen any scenarios so far that weren't better handled using the idioms we've already established. |
Joe, Did you send this to me by mistake? I'm not sharko666. On Mon, Oct 13, 2014 at 11:29 AM, Joe Cheng notifications@github.com
Marc-david Cohen | Chief Science Officer | +1.415.205.6295 | The power of many, the focus of one |
@Marccohen You probably got a copy of the message because you're watching the shiny repository on github. |
Hi Joe, Now, I found a solution but it might not be the solution as shiny is supposed to work. I have a global variable set in the reactiveValues function called actionCounter. Every time the button is pressed the buttoncounter is increased and is higher than the actionCounter. Inside the logic the action counter is set to the buttoncounter. Now I only test whether the actionCounter is lower than the buttonCounter. See code below. #server.R vars = reactiveValues(actionCounter=0) inside the observer for the textfieldurl = input$URL_input So there is a relative easy solution but if there were the possibility to reset the button counter it would have been simpler and easier to understand. Regards Christoph From: Marc Cohen [notifications@github.com] Joe, Did you send this to me by mistake? I'm not sharko666. On Mon, Oct 13, 2014 at 11:29 AM, Joe Cheng notifications@github.com
Marc-david Cohen | Chief Science Officer | +1.415.205.6295 | The power of many, the focus of one — |
Thanks for the feedback. This is the idiomatic way to handle such a situation: url <- reactive({
if (input$submit_URL == 0) {
return(NULL)
}
isolate(input$URL_input)
}) Then everywhere you want to access the URL, use It is a longstanding grievance against Shiny that we don't have wrapper functions for this idiom. |
@sharko666 I just merged a very longstanding pull request into master. With this change you can now do this instead: url <- reactive({
eventFilter(input$submit_URL, input$URL_input)
}) This basically means "the value of There is a complementary observeEvent(input$submit_URL, function() {
# Do something involving input$URL_input
}) The "do something" part of the code will be executed when and only when the button is clicked. |
@jcheng5 I just used the new version of Shiny - 10.2.9 for the new observeEvent function. It works great on my desktop version of R studio, but I am trying to run this using a portable R and Chrome install from a flash drive. This worked fine with shiny 10.2.1 because I was able to find a zip that worked for shiny 10.2.1. I have tried going though github, but am not sure how I can find (or create) a 10.2.9 zip that will work for a portable (32 bit) install of R. If you could point be in the right direction that would be much appreciated. Thanks :) |
@dakshvarma Is there a reason that devtools::install_github` wouldn't work with your portable R? |
@jcheng5 Got it working finally! devtools::install_github installs it by creating a local folder. The trick is to zip up the local folder, install a package from the zip in the portable install (with the zip in the same folder as portable R). Thanks for your help! |
i have the following case:
|
What does Reset do, clear it? What should the initial state of the plot On Tue, Nov 18, 2014 at 8:37 AM, Hratch notifications@github.com wrote:
|
Reset sets back the value of the matrix to be plotted to an initial value. That means the matrix can be calculated outside the renderPlot too right? |
In that case, it sounds like both Generate at Reset should affect not the initialMatrixValue <- ...
shinyServer(function(input, output, session) {
values <- reactiveValues(matrix = initialMatrixValue)
observe({
if (input$GEN_button == 0)
return()
values$matrix <- ... # Generate the matrix here
})
observe({
if (input$RES_button == 0)
return()
values$matrix <- initialMatrixValue
})
output$Result <- renderPlot({
plot(values$matrix) # or whatever
})
}) |
Thank you for your fast feedback/solution, you're great. |
I, too, find myself wanting to reset an action button. I don't find the following functionality in the thread so far, so I'll try it out for Joe... It has to do with using a conditional panel that looks at an action button value for its condition (this is in ui.R, not server.R). In a sidePanel I have something like:
then in a main panel I have something like
Now, at some point (maybe triggered by another action button, I would like to reset input.doit and re-display the first conditional panel, have the user re-specify inputs there, etc. Seems like it would be quite natural to have something like I would be very happy to hear the 'right and proper' way to do this, given that |
To get a 0 / 1 actionbutton without resetting:
|
I stumbled upon this issue, while looking for a way to write a single handler that can respond to a large number of individual (dynamically changing) action buttons. Here's an example of what I was trying to do: save_settings <- function()
{
xs <- seq(1,100,by=1)
result<-lapply(xs,function(x){
observeEvent(input[[paste0(x,"_save")]], {
if(!(input[[paste0(x,"_save")]]==0)){
# Save something for this value of x.
#input[[paste0(x,"_save")]] <- 0 # Could be a nice place to be able to reset to 0.
}
}
}
message(paste0(x,"_save: ",input[[paste0(x,"_save")]]))
})
input[[paste0(x,"_save")]]
})
return(result)
}
}) I could see the 'reset' to zero being useful in this case, but perhaps there's a better way of doing this. |
@mikebirdgeneau That's absolutely not necessary in this case. This is all you need to do: save_settings <- function() {
xs <- seq(1,100,by=1)
lapply(xs,function(x){
observeEvent(input[[paste0(x,"_save")]], {
# Save something for this value of x.
})
})
} |
@jcheng5 thanks - I'll give that a go! Appreciate the quick response. Cheers. |
I can see one argument for resetting an actionButton that I haven't seen mentioned here (apologies if it has been mentioned, and I missed it). I'd like to be able to copy the URL from the browser in which my shiny app is running, send it to somebody else, and have them be able to load the same page with all of the inputs automatically populated from the URL. I do not, however, want the actions executed by an actionButton to run automatically. (One example of this might be a page used to visualize data, with an actionButton that will trigger the writing of that data to a particular file. I want to be able to send a visualization of that data to somebody by sending them the URL to my page, but they may not want to write it to file upon page load). By default shiny can save/load all of its input variables to/from the URL, which is great most of the time, but can cause issues when it loads actionButtons with values > 0. In those cases, as in the example above, it will think that the user has clicked the actionButton when in reality he/she has not yet done so. This is a case in which the value of the actionButton does not matter, but the fact that it is not zero is important. Thanks for your help! |
That's not a built-in feature of Shiny; is there a specific package you're using to give you that functionality? |
You're right - this is part of a separate package (that is not yet publicly available). Thank you for the quick response. |
@nhpackard does library(shiny);library(shinyjs)
shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("showPanel","Show Panel!")
),
mainPanel(
useShinyjs(),
absolutePanel(id = "panel", class = "panel panel-default",
style = "z-index:100; display: none;",
div(style="margin:10px;",
h3("Hello World")
)
)
)
)
),
server = function(input, output) {
observeEvent(input$showPanel,{
toggle("panel")
})
}
) It's not using |
Hi Joe, I stuck around the similar problem related to the resetting of action button. My problem is On UI : I have 1 drag down which contains 2 values "Suntrust Bank" and "Huntington Bank". And below which i have 3 action buttons for 3 task : process data, download processed data and upload processed data. When i select Suntrust first time, below three action buttons are not executed unless i pressed them. However, whenever i select Huntington, below 3 buttons executed automatically (buttons were not pressed) . Could you please help me out how to resolve this ? Ideally i would like to have : when i change SunTrust to Huntington or and again Huntington to SunTrust, the below 3 buttons (process, download and upload) should not work unless and until i press them. Thanks in advance !! |
Like this: observeEvent(input$process, { On Tue, Jan 26, 2016 at 10:18 AM abhijeetgosavi notifications@github.com
|
Yes, exactly. Let me paste my server.r code here library(data.table)
library(shiny)
library(stats)
shinyServer(function(input, output, session) {
datasetInput <- reactive({
switch(input$Select,
"SunHE" = heloc.comp.rate,
"HunHE" = heloc.comp.rate1
)
})
observeEvent(input$goButton, {
output$MyData <- renderDataTable({
datasetInput()
})
})
observeEvent(input$Click, {
output$fill <- renderUI({
write.csv(datasetInput(), file.loc,row.names=FALSE)
})
})
observeEvent(input$Submit, {
output$fill <- renderUI({
write.csv(datasetInput(), Up.file.loc,row.names=FALSE)
})
})
}) ui.r shinyUI(fluidPage( sidebarLayout(
)) When i'm changing bank from Suntrust to Huntington from Drag n Down, below 3 actions buttons are executing automatically. |
Can we take the discussion over to shiny-discuss? Thanks. |
I have created new discussion - Resetting action buttons. Kindly have a look and let me know if you have any inputs. Thanks. |
was this ever resolved or did they just keep insisting that nobody needed it? I need it! :) |
I was wondering if there was a resolution to this as well. I need the actionButton reset because I have a conditionalPanel that depends on whether the button is clicked, but it has to be reset whenever the user switches options in my dropdown menu. |
I think you can use this code to determine if it's odd or even
x %% 2 == 0
does that work?
…On Thu, Mar 8, 2018 at 9:06 AM, Liquan Yang ***@***.***> wrote:
I was wondering if there was a resolution to this as well. I need the
actionButton reset because I have a conditionalPanel that depends on
whether the button is clicked, but it has to be reset whenever the user
switches options in my dropdown menu.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#167 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AK1uahF09NieR3_qn660YI8QVNfYtuz0ks5tcTrIgaJpZM4At9WK>
.
|
In general what you need is |
I ended up using shinyjs to create a hidden checkboxInput that would be toggled by several observers. Then, in my UI, I set up a conditionalPanel to check for the T/F value from the checkboxInput, and display the button if TRUE. |
I am experiencing a similar problem when using multiple embedded observeEvents, where a reset of the actionButton value would be useful. For example:
This structure works perfectly in the first instance. However, when triggering button1 for the second time, it skips straight to observeEvent button2, without input$button2 having been provided. A bit more investigating with browser() showed that input$button2 retains its value despite closing the modal and triggering input$button1 again, UNLESS a modalButton is used to dismiss the modal instead of removeModal(). A hard reset of the button in this case would be useful in conjunction with removeModal(), to prevent the app user from having to click a "Dismiss"-style modalButton every time. Previously I have used updateRadioButtons to reset inputs for a selection menu, but this doesn't work the same with actionButtons. I haven't found a suitable solution above, but I very much hope to be corrected by someone! Thanks a lot. |
that's an obviously useful feature - is there any piece of reasoning why this is not fixed??? |
I'm having the same issue which is really annoying when having two modals back-to-back where the first one shows missing data for a selection. Could not find suitable workaround either |
Ok. For future reference to people having the same problem as me. The easy solution for me was to include `
} Sorry for terrible formatting. Hope this helps somebody |
@TjebsC For future reference, you can work around this by giving Oh, ha, this exact scenario is laid out in
|
ok, I am a same problem.
I have this code inside an observeEvent to save every time I make changes to a map, the problem is that as soon as a parameter change is saved, I mean when I click on the save button, and it doesn't stop working; I would like it to only save when I click. |
A method written after I've read this issue and the last message of @jcheng5 about
|
can an actionbutton be reseted to 0 inside server.R?
let's say i have actionButton("b1","button1"). what could be the code for reseting the action button to 0?
The text was updated successfully, but these errors were encountered: