我正在开发一个闪亮的应用程序,其中用户的一些输入(保存在数据框中)用于在具有多个框的框线上绘制一条线(使用abline)。
在开发的第一阶段没有问题。一切看起来都很好。
要注意的是,由于该应用程序中有许多潜在的箱型图,我要求用户选择它想要为更友好的界面看到的箱型图。
由于我已经实现了选择选项,R似乎在使用“ abline”命令时遇到了麻烦。
在下面的代码中,您可以看到我使用的两种方法:
abline(h = UserData$X, col = "red")
从而导致以下错误消息:
Warning: Error in $: object of type 'closure' is not subsettable
[No stack trace available]
,可惜我无法解密。abline(h = input$Num_B, col = "red")
我不喜欢它,因为它不使用用户认可的数据框。这里没有错误消息,但也没有一行。有解决此问题的想法吗?
非常感谢大家,美好的一天!
我的简化代码供您使用:
library(shiny)
#UI:
# 1* 2 numeric input from user (Num_A & Num_B) which will be use as a line across the boxplots
# 2* Navbarmenu with 1 tab (for a simpler reading) where the user can chose to display one of 2 boxplots
# -> The boxplot are there but not the line defined by the input
#Server
# 1* Get the main database file from the computer and order the box plot for further use
# 2* Collect user's inputs in a dataframe
# 3* Construction of the plots
ui <- fluidPage(
############################## 1
navbarPage(title = "App title",
tabPanel("User's input tab",
titlePanel("Input from user"),
sidebarLayout(
sidebarPanel("Fancy sidebar"
),
mainPanel(
numericInput("Num_A","1rst user input", value = 1, min=0),
numericInput("Num_B","2nd user input", value = 1, min=0),
actionButton(inputId = "UserValid",label = "User says go!"),
)#end mainpanel
)#end sidebarlayour
)#end second tab,
############################## 2
navbarMenu(title = "Menu tab",
tabPanel("Graph panel",
titlePanel("Boxplot"),
sidebarLayout(
sidebarPanel(
selectInput("graph", "Choose a graph to view:",
choices = c("Plot1", "Plot2")),
actionButton(inputId = "BamUpdate", label = "Update")
),#end sidebarpanel
mainPanel(
plotOutput("selected_graph")
)#end mainpan
)#end sidebarlayout BaM
)#end tabPanel BaM
)#end navbarMenu
)#end Navbarpage
)#end ui
server <- function(input, output) {
############################## 1
DB1 <- read.csv2("~/Documents/Cours/Memoire/DT_2.0/ShinyDT/Main/DB1_Comp.csv", row.names = 1, sep=",", dec=".")
DB1$GRP<-factor(DB1$GRP, levels=c("PmPte+","PmPte-","ItEte+","ItEte-","Tm"))
############################## 2
UserData <- eventReactive(input$UserValid,{
data.frame(X=input$Num_A,Y=input$Num_B)
})
############################## 3
plot1 <- eventReactive(input$BamUpdate,{
boxplot(DB1$SBL~DB1$GRP, main="Plot 1 title", col=c("gray24","green","orangered","blue","saddlebrown"),ylab="Unit",cex.lab=1.2,cex.axis=1.2)
abline(h = UserData$X, col = "red")
})
plot2 <- eventReactive(input$BamUpdate,{
boxplot(DB1$SSS~DB1$GRP, main="Plot 2 title", col=c("gray24","green","orangered","blue","saddlebrown"),ylab="Unit",cex.lab=1.2,cex.axis=1.2)
abline(h = input$Num_B, col = "red")
})
graphInput <- eventReactive(input$BamUpdate,{
switch(input$graph,
"Plot1" = plot1(),
"Plot2" = plot2()
)
})
output$selected_graph <- renderPlot({
graphInput()
})
}#end server
shinyApp(ui = ui, server = server)