1

my code:-

library(shiny)

ui <- fluidPage(
    titlePanel("Find square of x"),
    numericInput("x","x:",5),
    uiOutput("y")
)

server <- function(input, output){
     output$y <- renderUI({
          numericInput("y","Square of x:",input$x * input$x)
     })
}

shinyApp(ui = ui, server = server)

In this app user can change the value of output "Square of x". Is there any way this can be prevented (means user input can be disabled in output).

Or anything like if a user modifies output "Square of x" than input "x" also get change accordingly.

1 Answer 1

5

Yes, we can use shinyjs for that:

library(shiny)
library(shinyjs)

ui <- fluidPage(
  useShinyjs(),
  titlePanel("Find square of x"),
  numericInput("x","x:",5),
  numericInput("y","Square of x:",NULL)
)

server <- function(input, output,session){

  observeEvent(input$x,{
    updateNumericInput(session, "y", value = input$x * input$x)
    disable("y")
  })

}

shinyApp(ui = ui, server = server)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.