在Shiny中使用readlines

在Shiny中使用readlines

本文介绍了在Shiny中使用readlines(prompt =)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 readlines(prompt =)函数接收输入的代码。您能告诉我Shiny中的哪个输入功能足以使此代码适应Shiny应用吗?

I have a code that takes inputs using the readlines(prompt = ) function. Could you tell me which input function in Shiny will be adequate to adapt this code to a Shiny app?

我需要一个交互功能,我不能在 selectInput()中使用简单的输入,因为我有一个许多 readlines(prompt =)语句。

I need an interactive function, I can't use a simple input with selectInput() because I have a lot of readlines(prompt = ) statements.

类似于此问题的东西:

Something similar to this question: Include interactive function in shiny to highlight "readlines" and "print"

推荐答案

弗洛里安的答案很好并且易于使用,我绝对建议您这样做!但是如果您热衷于使用提示作为输入,我会添加另一个解决方案,使用 javaScript

Florian's answer is nice and easy to use, I would definitely recommend that! But in case you are keen on using prompts for inputs I am adding another solution, using javaScript:

当用户按下 actionButton 并存储时,它显示提示它在输入变量中。 (不一定必须在按下按钮后)

This one shows a prompt when the user presses an actionButton and stores it in an input variable. (it doesn't necessarily have to be after a button press)

library(shiny)

ui <- fluidPage(
  tags$head(tags$script("
    $(document).on('shiny:inputchanged', function(event) {
      if (event.name === 'go') {
        var text = prompt('Write me something nice:');
        Shiny.onInputChange('mytext', text);
      }
    });"
  )),
  actionButton("go", "Click for prompt"),
  textOutput("txt")
)

server <- function(input, output, session) {
  output$txt <- renderText( {
    input$mytext
  })
}

shinyApp(ui, server)

这篇关于在Shiny中使用readlines(prompt =)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:05