我使用數據框從用戶界面接收輸入。爲了簡化,假設它是2行和2列。根據投入,我想繪製分佈圖。挑戰在於我需要以相同的方式呈現分佈,即以「矩陣」的格式呈現。R作爲renderTable元素的閃亮直方圖
我在下面提供了一個可重現的例子。我從錯誤消息中得出的結論如下:一旦我在輸入矩陣中輸入數據,接收矩陣就不能通過圖來代替其元素(通常是數字)。可能我應該告訴接收的數據框,它的元素不會是「標準的」,但我不知道如何。另外,也許我應該使用JavaScript或HTML來定義直方圖?
這是我ui.R和server.R的簡化版本:
ui.R:
shinyUI(navbarPage(
"My Application",
tabPanel("Component 1",
fluidPage(
tableOutput('decision_Matrix'),
tableOutput('decision_Matrix_plots')
)),
tabPanel("Component 2")
))
server.R:
shinyServer(
function(input, output) {
output$decision_Matrix <- renderTable({
matrix_input <- matrix(data=NA, nrow=2,ncol=2)
for (j in 1:2) {
for (i in 1:2) {
matrix_input[i,j] <- paste0("<input id='C", j, "_A", i, "' type='number' class='form-control shiny-bound-input' value='", input[[paste0("C", j, "_A", i)]], "'>")
}
}
rownames(matrix_input) <- c("alt1","alt2")
colnames(matrix_input) <- c("crit1","crit2")
matrix_input
},include.rownames=TRUE, sanitize.text.function = function(x) x)
output$decision_Matrix_plots <- renderTable({
matrix_plots <- data.frame()
for (j in 1:2) {
for (i in 1:2) {
n <- input[[paste0("C", j,"_A",i)]]
matrix_plots[i,j] <- hist(rnorm(n),breaks=10) # here is where it is not correct I think
}}
matrix_plots
})
})
任何幫助將是很大的讚賞。
謝謝!
^h
您可以設置斷點,看看有什麼N'的'值和類。 – Jean
目前還不清楚你想在matrix_plots [i,j]中擁有什麼樣的價值。 –