我正在构建一个复杂的Shiny App,其中包含许多表,这些表是作为函数的输出而生成的,为了简便起见,这里将其称为测试。
然后,我想显示这些表,这些表具有我通过该函数分配的正确的列名,但是它们以点而不是空格或括号显示。最重要的是,还显示了表格的名称(我不需要)
关于如何显示正确的列名的任何想法:var test 1和var test(2)?
下面,我的代码:
library(shiny)
library(ggplot)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("A","Test",choices=c(1,2,3)),
actionButton("go","GO")
),
mainPanel(
plotOutput("graph1"),
tableOutput("table1")
)
))
server <- function(input, output) {
test<-function(A){
C<-(1:3)
A<-as.numeric(A)
dfA<-data.frame(A,C)
colnames(dfA)<-c("var test 1","var test (2)")
g1<-dfA
g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
geom_point(shape=1)
outputs<-list("output1"=g1,
"output2"=g2)
}
model_output<-eventReactive(input$go,{
test(input$A)
})
output$graph1<-renderPlot({
model_output()[2]
})
output$table1<-renderTable({
model_output()[1]
})
}
shinyApp(ui = ui, server = server)
答案 0 :(得分:-1)
问题出在提取for i in range(len(df["feature2"])):
test = df.loc[i,"feature2"]
if isinstance(test, float):
print('yes')
else:
print('no')
元素中。应该是list
而不是[[
,因为当我们执行[
时,它仍然是具有一个元素的[
list
和
model_output()[[1]]
如果我们尝试重现该问题
model_output()[[2]]
完整代码
o1 <- list(g1 = data.frame(`var test 1` = 1, `var test (2)` = 1:3, check.names = FALSE))
o1[1]
$g1 # note it is still a `list`
# var test 1 var test (2)
#1 1 1
#2 1 2
#3 1 3
str(o1[1])
List of 1
# $ g1:'data.frame': 3 obs. of 2 variables:
# ..$ var test 1 : num [1:3] 1 1 1
# ..$ var test (2): int [1:3] 1 2 3
o1[[1]]
# var test 1 var test (2)
#1 1 1
#2 1 2
#3 1 3
-输出