【问题标题】:Load image or text in Shiny R在 Shiny R 中加载图像或文本
【发布时间】:2014-05-02 14:08:34
【问题描述】:

我想使用 R SHiny 制作一个简单的 Web 应用程序,通过提供路径并在单击按钮时将其显示在我的网页上,从硬盘驱动器加载图像。

我首先对文本执行此操作,例如显示路径,但是当我单击时我的按钮没有反应(我的意思是说它不打印消息)。

服务器.R:

shinyServer(function(input, output, session) {
  dt<-reactive({
  output$text1 <- renderText({ 
  paste("You have selected", input$obs)
   })
  }) 
})

ui.R:

shinyUI(pageWithSidebar(
  headerPanel("Fruits and vegetables!"),
  sidebarPanel(
    helpText("What do you see below?"),
    #imageOutput(outputId="images/1.png")
    numericInput("obs", "Number of observations to view:", 10),
    actionButton("get", "Get")
),
  mainPanel(textOutput("text1"))
))

【问题讨论】:

    标签: r shiny shiny-server


    【解决方案1】:

    对于反应式,您必须将使用您的输入的代码包装在 reactive 块中,但您必须在其外部设置 output 值。在这种情况下,您的示例应该是

     shinyUI(pageWithSidebar(
       headerPanel("Fruits and vegetables!"),
       sidebarPanel(
         helpText("What do you see below?"),
         #imageOutput(outputId="images/1.png")
         numericInput("obs", "Number of observations to view:", 10),
         actionButton("get", "Get")
       ),
       mainPanel(textOutput("text"))
     ))
    

     shinyServer(function(input, output, session) {
       dt <- reactive({
         paste("You have selected", input$obs)
       })
       output$text <- renderText({ dt() })
     })
    

    要动态使用imageOutput,您应该提供有关如何从输入中选择图像 URL 的更多信息。

    【讨论】:

    • 我明白了。然而,这段代码所做的只是动态更新变量,而不是在按下按钮“get”时更新。如何延迟操作直到按下按钮?
    • 我发现需要出现的是“提交按钮”,而不是操作!操作按钮有什么用?
    • 我为众多的cmets感到抱歉。关于图像 URL,我的 R 脚本中的逻辑将选择图像并将它们显示在页面上。我基本上需要从本地计算机向它提供路径名。
    猜你喜欢
    • 2016-09-25
    • 2022-06-15
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    • 2020-12-29
    • 2018-06-04
    • 2022-08-15
    相关资源
    最近更新 更多