Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the input value in shiny from server

Tags:

r

shiny

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
 })
like image 846
Rolando Tamayo Avatar asked Apr 07 '17 00:04

Rolando Tamayo


People also ask

How do you enter shiny data?

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.

What is shiny session?

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.

Which function is used to create shiny app?

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.


1 Answers

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.

like image 190
jamesguy0121 Avatar answered Sep 28 '22 10:09

jamesguy0121