【问题标题】:Why am I getting 'server not found' error in my shiny app?为什么我的闪亮应用程序中出现“找不到服务器”错误?
【发布时间】:2020-05-07 20:51:48
【问题描述】:

我正在尝试自己学习闪亮,到目前为止它非常有趣。我正在尝试在两个输入都来自用户的图表上绘制一个奇异点。我收到“shinyApp 中的错误(ui = ui,server = server):找不到对象'server'”。这是我的代码:

ui <- fluidPage(
  titlePanel("Title"),
  sidebarPanel(
  sliderInput(inputId ="x1", 'I', min = 4, max = 12, value = 4),
  sliderInput(inputId = "y1", 'Y', min = 0, max = 10, value = 1)),
  plotOutput("Scale")
  )

server() <- function(input, output){
  output$Scale <- renderPlot({
      ggplot(aes_string(x = input$x1, y = input$y1))+
        geom_point() })
}


shinyApp(ui = ui, server = server)

【问题讨论】:

  • 尝试在server 之后删除括号(),如下所示:server &lt;- function(input, output... ...另外,您在ggplot 语句中是否缺少data =
  • 删除括号有效,但我不知道我会在 data= 部分放什么

标签: r ggplot2 plot graph shiny


【解决方案1】:

这是一个完整的工作示例,希望对您有所帮助。

滑块输入将为您的绘图提供数字信息。如果放置在数据框中,这可能更容易概念化(见下文)。

aes 美学映射为您的绘图提供有关 x 和 y 轴的信息,并使用 data 指示要用于绘图的数据集。

最后,添加了限制以欣赏随着滑块变化在图形周围移动的点(否则,轴将自动重新缩放)。

您可以在ggplot2 上了解更多信息:

https://ggplot2.tidyverse.org/

library(ggplot2)
library(shiny)

ui <- fluidPage(
  titlePanel("Title"),
  sidebarPanel(
    sliderInput(inputId ="x1", 'I', min = 4, max = 12, value = 4),
    sliderInput(inputId = "y1", 'Y', min = 0, max = 10, value = 1)),
  plotOutput("Scale")
)

server <- function(input, output){
  output$Scale <- renderPlot({
    my_data <- data.frame(x = input$x1, y = input$y1)
    ggplot(aes(x = x, y = y), data = my_data)+
      geom_point() +
      xlim(4, 12) +
      ylim(0, 10)
  })
}

shinyApp(ui = ui, server = server)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 2016-05-23
    • 2023-03-15
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多