在Shiny中使用readlines(prompt =)

时间:2018-02-24 21:15:51

标签: r shiny console

我有一个使用readlines(prompt = )函数获取输入的代码。你能告诉我Shiny中的哪个输入函数足以使这个代码适应一个Shiny应用程序吗?

我需要一个交互式函数,我不能使用selectInput()的简单输入,因为我有很多readlines(prompt = )语句。

类似于这个问题:  Include interactive function in shiny to highlight "readlines" and "print"

1 个答案:

答案 0 :(得分:2)

Florian的答案很好用且很容易使用,我绝对会推荐!但是,如果您热衷于使用prompts输入,我将使用javaScript添加另一个解决方案:

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

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)
相关问题