![](/img/trans.png)
[英]if/ifelse statements in renderPlot() for a Shiny app (elementary)
[英]Isuue with renderPlot in my Shiny App
感謝您的建議。 在問自己的問題之前,我檢查了該問題,但無法解決問題。 我定義了一個向量var_name <-reactive(input $ xcol),然后將tableData [,c(“ var_name”)]用作hist函數的輸入,但沒有成功。
我正在構建一個應用程序,用戶可以在其中上傳自己的文件並進行一些分析。 我可以設法在每個用戶上載不同文件的selectInput中更新變量的名稱。 現在我的問題是我無法傳遞在selectInput中選擇的變量來構建直方圖。 如何將選擇作為輸入的變量傳遞給直方圖? 這是我的ui.r代碼。 一旦執行代碼,我在應用程序中遇到的錯誤就是“'closure'類型的對象不可子集化”。 有什么建議嗎? 謝謝
library(shiny)
ui<-fluidPage(
titlePanel(title = "My app"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Cargar archivo',
accept = c(
'text/csv',
'text/comma-separated-values',
'text/tab-separated-values',
'text/plain',
'.csv',
'.tsv'
)
),
checkboxInput('header', '¿Contiene Encabezado?', TRUE),
radioButtons('sep', 'Delimitador',
c(Comma=',',
"Punto y coma"=';',
Tab='\t'),
','),
radioButtons('quote', 'Quote',
c(Ninguna='',
'Dobles'='"',
'Simples'="'"),
'"'),
radioButtons('resume', 'Summary',
c('Individual',
'Múltiple'), selected = "Múltiple",
inline = TRUE),
conditionalPanel("input.resume === 'Individual'",
selectInput('xcol', 'Variable X', ""),
sliderInput("bins","Seleccione el número de clases",min=5, max = 15, value = 6),
radioButtons("color","Seleccione un color", c("Amarillo","Azul","Rojo","Gris"), selected = "Azul", inline = TRUE)
)
),
mainPanel(h3("Muestra del archivo cargado:"),
tableOutput('contents'),
verbatimTextOutput("summary"),
plotOutput("histog")
)
)
)
server<-function(input, output, session) {
tableData <- reactive({
inFile <- input$file1
if (!is.null(inFile)){
read.csv(inFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
}
else {
return(NULL)
}
})
observe({
updateSelectInput(
session,
"xcol",
choices=names(tableData()))
})
var_name<-reactive(input$xcol)
output$contents <- renderTable({
head(tableData())
})
output$summary <- renderPrint({
summary(tableData())
})
output$histog<-renderPlot({
hist(tableData[,c("var_name")],breaks= seq(0,10,l=input$bins+1), col(input$color))
})
}
shinyApp(ui = ui, server = server)
您的閃亮應用實際上存在幾個問題:
要被識別,顏色應該以這種方式編碼:
c(Amarillo="yellow",Azul="blue",Rojo="red",Gris="grey")
var_name
應該處理NULL
var_name<-reactive({ if(input$xcol!="") input$xcol else NULL })
反應值應始終與括號一起使用:
tableData() var_name()
這實際上是產生錯誤的原因
顏色參數應該這樣寫:
col=input$color
您應該檢查您的反應性值是否為NULL
if(!is.null(tableData())&&!is.null(var_name())) hist(tableData()[,var_name()],breaks= seq(0,10,l=input$bins+1), col=input$color)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.