2017-03-03 66 views
0

我想设置一个有点闪亮的应用程序来简化我的一个功能的使用。所以我想使用的功能是R闪亮文件上传,参加功能

create_rating <- function(data_path, x, y, z) 

输入String, int, int int 输出是matrix

library(shiny) 
library(NLP) 

create_rating <- function(data_path, x, y, z){} 

ui <- fluidPage(

    titlePanel("Review"), 
    sidebarLayout(
    sidebarPanel(
     fileInput("file1", "Choose .txt File", 
       accept=c("text/csv", 
          "text/comma-separated-values,text/plain")), 
     actionButton("update", "Upload!"), 
     hr(), 

     numericInput("good", "3* Rating",15), 
     numericInput("ok", "2* Rating",8), 
     numericInput("bad", "1* Rating",3)  
    ), 
    mainPanel(
     h4("Review"), 
     tableOutput("result_shiny") 
    ) 
    ) 

) 

server <- function(input, output) { 
    inFile <- reactive({input$file1}) 
    if(is.null(inFile())) 
    return(NULL) 

    x <- reactive({input$good}) 
    y <- reactive({input$ok}) 
    z <- reactive({input$bad}) 

    result <- reactive({ 
     input$update 
     withProgress({ 
      setProgress(message = "Processing review...") 
      physical_check(as.String(path), x(), y(), z()) 
     }) 
     }) 

    output$result_shiny <- renderTable({result()}) 
} 
# Run the application 
shinyApp(ui = ui, server = server) 

然后,它会打开一个窗口,布局配合却是露出了处理通知所有的时间和不结果。

或者我试图像

server <- function(input, output) { 
     output$result_shiny <- eventReactive(input$update,{ 
     inFile <- reactive({input$file1}) 
     x <- reactive({input$good}) 
     y <- reactive({input$ok}) 
     z <- reactive({input$bad}) 
     resultat <- reactive({ 
     withProgress({ 
      setProgress(message = "Processing review...") 
      physical_check(as.String(inFile()$datapath), x(), y(), z()) 
     }) 
     }) 

    }) 

} 

但有了这个功能的服务器部分,它打开的窗口中,我可以选择一个文件,按下上传按钮,然后什么都没有,也没有处理通知。

在此先感谢!

回答

0

我已经加入了条件if(!is.null(inFile()))这样函数create_rating(我假设你指的功能create_rating,而不是physical_check,因为在你的代码的任何地方定义无此功能)来改变你的函数的服务器部分只有在文件上传后才能调用。

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

    x <- reactive({input$good}) 
    y <- reactive({input$ok}) 
    z <- reactive({input$bad}) 
    observe({ 
    if(!is.null(inFile())){ 
     result <- reactive({ 
     input$update 
     withProgress({ 
      setProgress(message = "Processing review...") 
      create_rating(as.String(path), x(), y(), z()) 
     }) 
     }) 
     output$result_shiny <- renderTable({result()}) 
    } 

    }) 

} 

希望它有帮助!

+0

非常感谢,工作正常。虽然我不确定,但为什么Shiny不接受我的尝试。 –