强制性引入的NA,但我不想仅删除警告

时间:2018-12-03 21:42:39

标签: r shiny

一个闪亮的应用程序下面,该应用程序旨在绘制

的和
  • csv的值:as.numeric(as.character(s $ ascor [1],na.rm = TRUE))
  • 滑块值的值:input $ green / 100

问题在于情节不是动态的; y =该图上的NA(参见所附图片);我不知道怎么了

我已经检查了这一点,但它只是说要删除警告,因此不能解决剧情问题==> How to avoid warning when introducing NAs by coercion

代码下方:

library(shiny)
library(ggplot2)

# Define UI for slider demo app ----
ui <- fluidPage(

  # App title ----
  titlePanel("Sliders"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar to demonstrate various slider options ----
    sidebarPanel(

      # Input: Simple integer interval ----
      sliderInput("green", "Green:",
                  min = 0, max = 200,
                  value = 50),

      # Input: Decimal interval with step value ----
      sliderInput("blue", "Blue:",
                  min = 0, max = 200,
                  value = 50, step = 0.1),

      # Input: Specification of range within an interval ----
      sliderInput("red", "Red:",
                  min = 0, max = 200,
                  value = 50),

       # Input: Specification of range within an interval ----
      sliderInput("yellow", "Yellow:",
                  min = 0, max = 200,
                  value = 50),

      sliderInput("purple", "Purple:",
                  min = 0, max = 200,
                  value = 50),

      sliderInput("brown", "Brown:",
                  min = 0, max = 200,
                  value = 50),

      sliderInput("black", "Black:",
                  min = 0, max = 200,
                  value = 50),
      sliderInput("white", "White:",
                  min = 0, max = 200,
                  value = 50),

      sliderInput("pink", "Pink",
                  min = 0, max = 200,
                  value = 50),
      sliderInput("orange", "Orange",
                  min = 0, max = 200,
                  value = 50),
      sliderInput("gold", "Gold",
                  min = 0, max = 200,
                  value = 50)
    ),



    # Main panel for displaying outputs ----
    mainPanel(

      # Output: Table summarizing the values entered ----
      tableOutput("values"),
      plotOutput('distPlot')  

    )
  )
)

# Define server logic for slider examples ----
server <- function(input, output) {



  # Reactive expression to create data frame of all input values ----
  sliderValues <- reactive({

    data.frame(
      Name = c("Total"),
      Value = as.character(c(input$green/100*as.numeric(as.character(s$ascor[[1]], na.rm=TRUE))+input$blue/100*as.numeric(as.character(s$ascor[[2]], na.rm=TRUE))+input$red/100*as.numeric(as.character(s$ascor[[3]], na.rm=TRUE))+input$yellow/100*as.numeric(as.character(s$ascor[[4]], na.rm=TRUE))+input$purple/100*as.numeric(as.character(s$ascor[[5]], na.rm=TRUE))+input$brown/100*as.numeric(as.character(s$ascor[[6]], na.rm=TRUE))+input$black/100*as.numeric(as.character(s$ascor[[7]], na.rm=TRUE))+input$white/100*as.numeric(as.character(s$ascor[[8]], na.rm=TRUE))+input$pink/100*as.numeric(as.character(s$ascor[[10]], na.rm=TRUE))+input$orange/100*as.numeric(as.character(s$ascor[[11]], na.rm=TRUE))+input$gold/100*as.numeric(as.character(s$ascor[[12]], na.rm=TRUE)))),
                             stringsAsFactors = FALSE)

  })



  # Show the values in an HTML table ----
  output$distPlot <- renderPlot({

    # Render a barplot
    sliderValues <- data.frame(
      Name = c("Total"),
      Value = as.character(c(input$green/100*as.numeric(as.character(s$ascor[[1]], na.rm=TRUE))+input$blue/100*as.numeric(as.character(s$ascor[[2]], na.rm=TRUE))+input$red/100*as.numeric(as.character(s$ascor[[3]], na.rm=TRUE))+input$yellow/100*as.numeric(as.character(s$ascor[[4]], na.rm=TRUE))+input$purple/100*as.numeric(as.character(s$ascor[[5]], na.rm=TRUE))+input$brown/100*as.numeric(as.character(s$ascor[[6]], na.rm=TRUE))+input$black/100*as.numeric(as.character(s$ascor[[7]], na.rm=TRUE))+input$white/100*as.numeric(as.character(s$ascor[[8]], na.rm=TRUE))+input$pink/100*as.numeric(as.character(s$ascor[[10]], na.rm=TRUE))+input$orange/100*as.numeric(as.character(s$ascor[[11]], na.rm=TRUE))+input$gold/100*as.numeric(as.character(s$ascor[[12]], na.rm=TRUE)))),
                             stringsAsFactors = FALSE)
      p <- ggplot(sliderValues(), aes(x=Name, y=Value)) +geom_bar(stat = "identity")
 print(p)


  })


}


shinyApp(ui, server)

所以我收到此错误消息:

Listening on http://127.0.0.1:5216
Warning in data.frame(Name = c("Total"), Value = as.character(c(input$green/100 *  :



Listening on http://127.0.0.1:5216
Warning in data.frame(Name = c("Total"), Value = as.character(c(input$green/100 *  :
  NAs introduits lors de la conversion automatique
Warning in data.frame(Name = c("Total"), Value = as.character(c(input$green/100 *  :
  NAs introduits lors de la conversion automatique
Warning in data.frame(Name = c("Total"), Value = as.character(c(input$green/100 *  :

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

感谢How to read in numbers with a comma as decimal separator?

CSV文件采用欧式格式,使用逗号代替小数点,即0.5代替0.5。 我更改了数据集,以使R将数据视为数字而不是字符串。

谢谢您的帮助!