我是R-shiny應用程序的新手,我的應用程序非常簡單。它有兩個選項卡,第一,我上傳一個文件,如csv,然後在第二個選項卡,我選擇將被繪製的列,我的解決方案分散在幾個例子,每個不同於我的,我想上傳的數據集可以被看到,並且可以在所有功能中使用,而不僅僅是在上傳時。如何繪製使用閃亮上傳的數據集?
我server.R
library(shiny)
shinyServer(function(input, output) {
output$contents <- renderTable({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
})
output$MyPlot <- renderPlot({
x <- contents()$contents[, c(input$xcol, input$ycol)]
bins <- nrow(contents())
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
ui.R
library(shiny)
library(datasets)
shinyUI(fluidPage(
titlePanel("Column Plot"),
tabsetPanel(
tabPanel("Upload File",
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv'))
),
mainPanel(
tableOutput('contents')
)
)
),
tabPanel("First Type",
pageWithSidebar(
headerPanel('My First Plot'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(content)),
selectInput('ycol', 'Y Variable', names(content),
selected=names(content)[[2]])
),
mainPanel(
plotOutput('MyPlot')
)
)
)
)
)
)
我一直在努力,這一點,但我剛開始是這樣,我該怎麼辦嗎?
爲了獲得幫助,我建議您提供一個.csv文件,以便在您的閃亮應用中使用。 – aelwan