我使用数据框从用户界面接收输入。为了简化,假设它是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]中拥有什么样的价值。 –