Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R.基本问题_R_Shiny - Fatal编程技术网

R.基本问题

R.基本问题,r,shiny,R,Shiny,我收到了两个我并不完全理解的警告: Warning in if (file == "") { : the condition has length > 1 and only the first element will be used Warning: Error in file: invalid 'description' argument 166: file 165: parse 163: renderPlot [...app.R#51] 161: func 1

我收到了两个我并不完全理解的警告:

Warning in if (file == "") { :
  the condition has length > 1 and only the first element will be used
Warning: Error in file: invalid 'description' argument
  166: file
  165: parse
  163: renderPlot [...app.R#51]
  161: func
  121: drawPlot
  107: <reactive:plotObj>
   91: drawReactive
   78: origRenderFunc
   77: output$Minimum_Rates
    1: runApp
if(file==“”)中的警告{code> 条件的长度大于1,并且只使用第一个元素 警告:文件中有错误:无效的“description”参数 166:文件 165:解析 163:renderPlot[…应用程序R#51] 161:func 121:绘图 107: 91:反应性 78:origRenderFunc 77:产出美元最低价格 1:runApp 作为R和Shiny的初学者,我不知道自己做错了什么。这个程序可能有很多错误,但如果有人能帮我解决这两个当前错误,那就太棒了。下面是我的代码:

library(shiny)
library(ggplot2)
library(dplyr)
library(rlang)
library(shinyWidgets)
library(rstudioapi)

ui <- fluidPage(


  # Give the page a title
  titlePanel("Rate Analysis"),

  # Generate a row with a sidebar
  sidebarLayout(      

    # Define the sidebar with one input
    sidebarPanel(
      selectInput("ProductType","Product Type: (Choose One)",choices=c("t","r")),
      selectInput("inSelect","Carrier: (Choose One)",choices=unique(c(t_rates_names,r_rates_names))),
      selectInput("Category","Category: (Choose One)",choices=c("Age","Term","Band","Class","Gender")),
      sliderInput("discount","% Discount:",min=0,max=100,value=0),
      width=3
    ),

    # Create a spot for the barplot
    mainPanel(
      plotOutput("Minimum_Rates")  
    )

  )
)

server <- function(input, output, session) {
  observe({
    req(input$ProductType)
    x<-sym(input$ProductType)
    updateSelectInput(session,"inSelect",label=paste("test"),choices=eval(parse(text=paste0(x,"_rates_names"))))
  })

  output$Minimum_Rates<-renderPlot({
    req(input$inSelect)
    req(input$Category)
    req(input$discount)
    req(input$ProductType)
    carrier<-(input$inSelect)
    carrier<-eval(parse(text=carrier))
    category<-sym(input$Category)
    discount<-input$discount
    string_name=deparse(substitute(carrier))
    fee_name=eval(parse(paste0(substr(string_name,1,nchar(string_name)-6),"_fees")))
    carrier<-discountRatesAndFindNewPrems(carrier,discount/100,fee_name)
    tMinTable<-removeTheseRatesAndFindMinimumRates(t_list_rates)
    if(as_string(input$ProductType)=="t"){
      carrier %<%
        createRatesComparedToTMin(carrier) %<%
        original_percent_higher<-Percent_Higher %<%
        findRatesFromPrems(carrier,fee_name) %<%
        original_rates<-`Rates per Thousand` %<%
        group_by(!!!category) %>%
        summarise(Current_Comparison=sum(original_percent_higher),Hypothetical_Comparison=sum(New_Percent_Higher)) %>%
        ggplot(aes_string(input$category,"Current_Comparison"))+geom_bar(stat="identity",position="dodge") + geom_text(aes(label=scales::percent(Current_Comparison)),size=3.2,vjust=-0.5,position=position_dodge(width=1))
    }
    else{
      rMinTable<-removeTheseRatesAndFindMinimumRates(r_list_rates)
      carrier$Percent_Higher<-original_percent_higher
      carrier<-createNewRatesComparedToRMin(carrier)
      carrier%>%
        group_by(!!!category) %>%
        summarise(Current_Comparison=sum(original_percent_higher),Hypothetical_Comparison=sum(New_Percent_Higher))
        ggplot(aes_string(input$Category,"Current_Comparison"))+geom_bar(stat="identity",position="dodge") + geom_text(aes(label=scales::percent(Current_Comparison)),size=3.2,vjust=-0.5,position=position_dodge(width=1))  
    }
  })
}
shinyApp(ui=ui,server=server)
库(闪亮)
图书馆(GG2)
图书馆(dplyr)
图书馆(rlang)
图书馆(shinyWidgets)
图书馆(rstudioapi)

ui您的第一个警告与执行
x一个好问题相同,因此是小的、自包含的和(通常)的询问一个问题。我建议创建一个非常小的闪亮应用程序来复制您的问题。事实上,其他人不能使用您的代码,因为有很多函数我们也无法访问。我认为input$ProductType一次只能是一个项?或者input是一个向量?您确定这就是产生错误的原因吗?我同意h SYMBOLXAU。您正在
if
语句中使用多个条件。请改为尝试
ifelse
。这将允许您测试多个条件。