Как получить позицию курсора в Shiny textareaInput - PullRequest
0 голосов
/ 20 мая 2018

Кто-нибудь знает, как я могу в блестящем приложении получить позицию курсора внутри textAreaInput?

library(shiny)

ui <- fluidPage(
  textAreaInput("hop"
                ,label="textarea",value = "Supercalifragilisticexpialidocious"),
  verbatimTextOutput("out")
)

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

  output$out <- renderText({
    "here I would like to get the cursor position (an interger?) \n inside que textArea"

  })

}

shinyApp(ui, server)

Я думаю, что мне нужно использовать JavaScript, но я не знаю, с чего начать.

С уважением

1 Ответ

0 голосов
/ 20 мая 2018

Я нашел решение:

library(shiny)

ui <- fluidPage(tags$head(tags$script(
  'Shiny.addCustomMessageHandler("prout",
  function(NULL) {

   var ctl = document.getElementById("hop");
    var startPos = ctl.selectionStart;
  var endPos = ctl.selectionEnd;
  alert(startPos + ", " + endPos);

  });'
    )),
  textAreaInput("hop"
                ,label="textarea",value = "Supercalifragilisticexpialidocious"),
  verbatimTextOutput("out"),
  actionButton("hop","hop")
)

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

  output$out <- renderText({
    "here I would like to get the cursor position (an interger?) \n inside que textArea"

  })

  observeEvent(input$hop,{
    message("hop")
    session$sendCustomMessage(type="prout",message=list(NULL))
  })
}

shinyApp(ui, server)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...