我的代码没有正确部署R Jmeter 板,这是什么问题?

gk7wooem  于 2023-04-27  发布在  其他
关注(0)|答案(1)|浏览(103)

我对R Dashboard非常陌生(从昨天开始使用它)。本质上,代码的目的是进入我的C上的一组文件夹和子文件夹:驱动器,然后根据下拉菜单的选择,它会显示该目录中的“.png”文件。当我在同一页面中使用“ui.R”和“server.R”编写整个内容并使用

shinyapp(ui, server)

它工作得很好,但是当我想使用

deployApp(appName = "Name of the app")

为了这个目的,创建“ui.R”和“server.R”函数,虽然它确实构建了应用程序,但它不会显示下拉菜单中的文件或.png文件。我的“ui.R”代码如下:

library(shiny)
library(png)
library(shinyFiles)
library(dplyr)
library(ggplot2)
library(rsconnect)

# Define the directory paths
main_dir <- "C:/Users/username/Dropbox/user/Academic Paper/Data Files/Data/Plots"
annual_dir <- file.path(main_dir, "Annual")
quarterly_dir <- file.path(main_dir, "Quarterly")

# Define the country names (i.e., the three-letter folder names)
country_names <- list.files(annual_dir, recursive = FALSE) 

# Define the plot types
plot_types <- c("Difference from base", "Level")

ui <- fluidPage(
  column(width = 3, 
         selectInput("country", "Select Country", choices = country_names),
         selectInput("freq", "Select Frequency", choices = c("Annual", "Quarterly")),
         selectInput("folder", "Select Plot Type", choices = plot_types),
         uiOutput("file_selector")
  ),
  column(width = 9, 
         imageOutput(outputId = "plot")
  )
)

而“server.R”文件如下:

library(shiny)
library(png)
library(shinyFiles)
library(dplyr)
library(ggplot2)
library(rsconnect)

server <- function(input, output, session) {
  # Initialize variable name
  previous_country <- ""
  
  file_list <- reactive({
    # Change variable name only if country changes
    if (input$country != previous_country) {
      previous_country <<- input$country
      message("Updating variable name...")
    }
    chosen_path <- file.path("C:/Users/username/Dropbox/user/Academic Paper/Data Files/Data/Plots", input$freq, input$country, input$folder)
    png_files <- list.files(chosen_path)
    png_files <- png_files[!grepl("^(asl|asd|ql|qd)", png_files)]
    png_files <- gsub("\\.png$", "", png_files) # remove ".png" extension
    return(png_files)
  })
  
  output$file_selector <- renderUI({
    selectInput(inputId = "file", label = "Select a file", 
                choices = file_list())
  })
  
  output$plot <- renderPlot({
    # Get the selected directory path based on the input values
    chosen_file <- file.path("C:/Users/username/Dropbox/user/Academic Paper/Data Files/Data/Plots", input$freq, input$country, input$folder, paste0(input$file, ".png"))
    
    # Display the PNG file as a plot
    #png(chosen_file)
    img <- readPNG(chosen_file)
    grid::grid.raster(img)
    #dev.off()
  }, height = 600, width = 800)
}

我做错了什么?
先谢谢你了!

mftmpeh8

mftmpeh81#

服务器部分似乎没有运行。试着把线

shinyapp(ui, server)

(with正确的文件名),然后像以前一样运行“deployApp()”。

相关问题