press Button “enter” key action in shiny Math.random()

Published by onesixx on

특정 페이지에서만 js를 실행하는 가장 좋은 방법
\ttags$head(tags$script(HTML(
\t\t"$(document).keyup(function(event) {
\t\t\tif ($('#logInsignin').length > 0) { 
\t\t\t\tif (event.keyCode == 13) {
\t\t\t\t\t$('#logInsignin').click();
\t\t\t\t} 
\t\t\t}
\t\t});"
\t))),
removeUI(selector = "button#logInsignin")

removeUI(selector = "button#logInsignin")

removeUI(selector = “button#logInsignin”)

removeUI(selector = "button#logInsignin")

#tags$head(tags$script(src = "../../www/AAA.js")),
tags$head(tags$script(HTML(
  "$(document).keyup(function(event) {
    if ($('#BB').is(':focus') && (event.keyCode == 13)) {
      $('#CC').click();
    }
  });"
))),

  	# tags$head(tags$script(src = "enter_button.js")),

  	  tags$head(tags$script(HTML(
  	  	"$(document).keyup(function(event) {
  	  		if ($('#logInpassword').is(':focus') && (event.keyCode == 13)) {
  	  			$('#logInsignin').click();
  	  		}
  	  	});"
  	  ))),

https://stackoverflow.com/questions/31415301/shiny-responds-to-enter

library(shiny)

ui <- fluidPage(
    ##############
    tags$script(
        '$(document).on("keyup", function(e) {
            if(e.keyCode == 13){Shiny.onInputChange("ENTERKeyPressed", Math.random());}
        });'
    ),
    #############
    textInput( "logInusername",    "Login",    placeholder = "Username"),
    passwordInput("logInpassword", "PASSWORD", placeholder = "Password"),
    actionButton( "logInsignin",   "Sign in"),br(),
    
    verbatimTextOutput("result")
)

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

    observeEvent({input$logInsignin 
                  input$ENTERKeyPressed}, {
        if((input$logInusername)!="") {
            output$result <- renderText({
                paste0("Welcome ", input$logInusername)
            })
        }else{
            print("Your username is incorrect - please try again.")
        }
    })
}

shinyApp(ui, server)

js <- '
$(document).on("keyup", function(e) {
if(e.keyCode == 13){
Shiny.onInputChange("keyPressed", Math.random());
}
});
'
library(shiny)

ui <- fluidPage(
    tags$script(js),
    textInput("title", label = "Title"),
    plotOutput("ggplot")
)
server <- function(input, output, session){
    Title <- reactiveVal()
    observeEvent(input[["keyPressed"]], {
        Title(input[["title"]])
    })
    output[["ggplot"]] <- renderPlot({
        ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) +
            geom_point() +
            ggtitle(Title())
    })
}
shinyApp(ui, server)

Categories: PjR-Shiny

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x