0

我想使用 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"))
))
4

1 回答 1

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 的更多信息。

于 2014-03-25T02:02:31.170 回答