Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.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_Prediction - Fatal编程技术网

R 发光误差函数

R 发光误差函数,r,shiny,prediction,R,Shiny,Prediction,我已经苦苦挣扎了好几个小时,想弄清楚我闪亮的应用程序到底出了什么问题。下面是服务器和ui,以及为服务器进行预测的函数 当我在文本框中写入时,反应性确实起作用,但出现了相同的错误。我不是一个闪亮的专家。这是我的第二个应用程序 当我运行它时,我会看到下面的应用程序(图片): 请帮忙 功能: library(tidyr) library(dplyr) library(quanteda) library(stringr) ## Read-in frequencies df1 <- readRDS

我已经苦苦挣扎了好几个小时,想弄清楚我闪亮的应用程序到底出了什么问题。下面是服务器和ui,以及为服务器进行预测的函数

当我在文本框中写入时,反应性确实起作用,但出现了相同的错误。我不是一个闪亮的专家。这是我的第二个应用程序

当我运行它时,我会看到下面的应用程序(图片):

请帮忙

功能:

library(tidyr)
library(dplyr)
library(quanteda)
library(stringr)

## Read-in frequencies
df1 <- readRDS("./App/nextword/g1.rds")
df2 <- readRDS("./App/nextword/g2.rds")
df3 <- readRDS("./App/nextword/g3.rds")
df4 <- readRDS("./App/nextword/g4.rds")

texti <- "i, Don't think"
texti <- corpus(texti)
texti <- corpus(tolower(texti))
## Clean input
texti <- tokenize(texti,
               remove_numbers = TRUE,
               remove_punct = TRUE,
               remove_symbols = TRUE,
               remove_separators = TRUE,
               remove_twitter = TRUE,
               remove_hyphens = TRUE,
               remove_url = TRUE,
               concatenator = " ",
               verbose = FALSE)

texti <- dfm(texti)
texti <- data.frame(word = featnames(texti), row.names = NULL, stringsAsFactors = FALSE)

p <- function(texti) {

        if(texti[1, ] == "" & texti[2, ] == "" & texti[3, ] == "") {
                prediction = df1 %>%
                        select(word, Frequency)

        }   else if(texti[1, ] %in% df4$w1 & texti[2, ] %in% df4$w2 & texti[3, ] %in% df4$w2) {
                prediction = df4 %>%
                        filter(w1 %in% texti[1, ] & w2 %in% texti[2, ] & w3 %in% texti[3, ]) %>%
                        select(w4, Frequency)     

        }   else if(texti[1, ] %in% df3$w1 & texti[2, ] %in% df3$w2) {
                prediction = df3 %>%
                        filter(w1 %in% texti[1, ] & w2 %in% texti[2, ]) %>%
                        select(w3, Frequency)

        }   else if(texti[1, ] %in% df2$w1) {
                prediction = df2 %>%
                        filter(w1 %in% texti[1, ]) %>%
                        select(w2, Frequency)

        }   else{
                prediction = df1 %>%
                        select(word, Frequency)
        }

        return(prediction)
}

因此,我认为我的'p'函数产生了不正确的维数错误(例如texti[1,])。texti是一个数据帧[1列,3行]。你知道我该如何克服这个问题吗。我想要编写的代码是:如果每行texti都在df中,那么返回最高频率(愚蠢的退避模型)。因为您的问题不在于
shinny
本身,我建议在shinny应用程序之外重写代码的主要操作。重新发布操作的最低版本,您应该会得到更多帮助。在没有访问所有数据的情况下,
df1@ChiPak这里是主要的操作(当我执行p(“i”、“want”和“))。该操作显示了最常用单词的表(1:3)。我认为我的问题来自我如何在闪亮的应用程序中获得输入<代码>p
library(shiny)
library(shinythemes)
library(markdown)

shinyServer(function(input, output, session) {

        pt1 <- reactive(p(input$texti)[1])
        output$texti1 <- pt1
        observeEvent(input$b1, { 
                updateTextInput(session, "texti",
                                value = paste(input$texti, pt1()))
        })
        pt2 <- reactive(p(input$texti)[2])
        output$texti2 <- pt2
        observeEvent(input$b2, { 
                updateTextInput(session, "texti",
                                value = paste(input$texti, pt2()))
        })
        pt3 <- reactive(p(input$texti)[3])
        output$texti3 <- pt3
        observeEvent(input$b3, { 
                updateTextInput(session, "texti",
                                value = paste(input$texti, pt3()))
        })
})
library(shinythemes)
shinyUI(fluidPage(
        theme = shinytheme("darkly"),
        tags$hr(),
        titlePanel("Next Word Prediction Application"),
        tags$hr(),

        mainPanel(tabsetPanel(
                tabPanel("Prediction",
                         sidebarLayout(
                                 sidebarPanel(
                                         width = 3,
                                         tags$p(""),
                                         tags$h5("Predicted next word:"),
                                         flowLayout(
                                                 actionButton("b1", label = textOutput("texti1")),
                                                 actionButton("b2", label = textOutput("texti2")),
                                                 actionButton("b3", label = textOutput("texti3"))
                                          )
                                 ),
                                 mainPanel(
                                         tags$p(""),
                                         tags$h5("Please, enter your text:"),
                                         h4(tags$textarea(id = "texti", rows = 1, cols = 30, "")))
                         )),
                tabPanel("About", includeMarkdown("README.md"))
        ))
))