I have an action botton with id=do
, i would want change the value of and input called rhm_clic when the acction boton is clicked. I have this at the moment.
observeEvent(input$do,{
input$rhm_clic<-NULL
})
To add an input in a Shiny app, we need to place an input function *Input() in the ui object. Each input function requires several arguments. The first two are inputId , an id necessary to access the input value, and label which is the text that appears next to the input in the app.
Description. Shiny server functions can optionally include session as a parameter (e.g. function(input, output, session) ). The session object is an environment that can be used to access information and functionality relating to the session.
shinyApp. Finally, we use the shinyApp function to create a Shiny app object from the UI/server pair that we defined above. We save all of this code, the ui object, the server function, and the call to the shinyApp function, in an R script called app.
There is an alternative to this which uses JS which I found to be very useful in some cases. This allows you to not have to use the update***input
functions. Additionally, the input doesn't even need to have been previously defined.
library(shiny)
ui <- fluidPage(
tags$script("
Shiny.addCustomMessageHandler('rhm_clic', function(value) {
Shiny.setInputValue('rhm_clic', value);
});
")
# additional UI code
)
server <- function(input, output, session) {
observeEvent(input$do, {
session$sendCustomMessage("rhm_clic", 'null')
})
# Additional server code
}
shinyApp(ui, server)
This is a good article by Joe Cheng laying out how to use this framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With