【问题标题】:Shiny R, Plot, ShinyAppShiny R, 情节, ShinyApp
【发布时间】:2017-06-12 12:57:35
【问题描述】:

我正在尝试用 Shiny R 编写一个简单的应用程序。 我想有两个输入(x 和 y)并绘制相对散点图。代码如下

library(shiny)

ui<-fluidPage(
headerPanel('Plot'),

sidebarPanel(
sliderInput(inputId = 'x',label='X', value = 1,min=1,max=3),


sliderInput(inputId = 'y',label='Y', value = 1,min=1,max=3)
),

mainPanel(
plotOutput('plot')
)
)

server<-function(input,output) {
x <- reactive({input$x})

y <- reactive({input$y})

output$plot <- renderPlot({plot(x,y)}) 
}


shinyApp(ui=ui, server=server)

代码产生错误,

cannot coerce type 'closure' to vector of type 'double'

我该如何纠正这个问题?

非常感谢

【问题讨论】:

    标签: r plot shiny


    【解决方案1】:

    X 和 Y 是函数,因此请在其中添加 ()

    output$plot &lt;- renderPlot({plot(x(),y())})

    【讨论】:

      【解决方案2】:

      您可以改用此服务器参数:

      server <- function(input,output) {
        output$plot <- renderPlot(plot(input$x,input$y)) 
      }
      

      【讨论】:

        【解决方案3】:

        input 值已经是响应式的,因此无需将它们包装在 reactive() 函数中。以一种更整洁、更有效的方式让您焕发光彩:

        library(shiny) {
        
            ui<-fluidPage(
            headerPanel('Plot'),
        
            sidebarPanel(
                sliderInput(inputId = 'x', label= 'X', value = 1, min= 1, max= 3),
                sliderInput(inputId = 'y', label= 'Y', value = 1, min= 1, max= 3)
            ),
        
            mainPanel(plotOutput('plot'))
        
            server<-function(input, output) {
                output$plot<- renderPlot({
                plot(input$x, input$y)
            }) 
        
        }
        
        shinyApp(ui= ui, server= server)
        

        【讨论】:

          猜你喜欢
          • 2021-08-12
          • 2021-12-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-12-19
          • 2019-08-29
          • 1970-01-01
          • 2021-09-01
          相关资源
          最近更新 更多