首页 > 解决方案 > R Shiny 应用程序不会上传文件或显示绘图

问题描述

希望有人能帮忙!

我正在尝试创建一个 R 闪亮的应用程序,它允许我上传文件以及在不同的选项卡中显示图。当我不引入选项卡时,我的文件上传代码有效 - 不知道为什么这会影响任何事情。

尽管代码在闪亮的应用程序之外工作,但我似乎也无法显示我的 ggplot。

这是我当前的代码(我知道我的小部件还没有做任何事情......):

ui <- fluidPage(

   # Application title
   titlePanel(h1("Title", align = "center")),

   # Upload file
   fileInput("upload", "Data file:", buttonLabel = "Select File", multiple = FALSE),
   tableOutput("files"), 
   hr(),

   # Tabs for Display Options
   tabsetPanel(
     tabPanel("Table 1", tableOutput("table")),
     tabPanel("Plot1", plotOutput("distPlot")),
     tabPanel("Table 2", tableOutput("table")),
     tabPanel("Plot 2",plotOutput("distPlot")),
     tabPanel("Summary", verbatimTextOutput("summary"))
   ),

   # Sidebar with interactive widgets 
   sidebarLayout(
      sidebarPanel(
      # Radio Buttons for Data Normalization
      radioButtons("radio", label = h3("Pick:"),
                   choices = list("1" = 1, "1" = 2), selected = 1),
         hr(),

      # Checkbox for whether outliers should be included
      checkboxInput("outliers", "Show outliers", FALSE)
      ),
      mainPanel(
         h1("test...")
      )
   )
)

# Server
server <- function(input, output) {

  # You can access the value of the widget with input$file
  output$files <- renderTable(input$upload)

  # Distribution Plots
  output$distPlot <- renderPlot({
    p <- ggplot(data=dat, aes(column1)) + geom_density(aes(y = ..count..), fill = "lightgray")
    print(p)
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

Dat 只是一个数据框,在 2 列(名为“column1”)的每一列中有 104 个值。不知道如何在这里分享,但可以是任何东西,只要我能让它显示出来。

谢谢!!

标签: rshiny

解决方案


推荐阅读