gpt4 book ai didi

mysql - 从 Shiny 的 renderUI 中获取

转载 作者:行者123 更新时间:2023-11-29 08:16:36 24 4
gpt4 key购买 nike

我正在构建一个 Shiny 的应用程序,用于从数据库进行数据可视化。我正在尝试使用 renderUI 中的输入值运行 ggplot 但出现错误

Error in na.omit(xVariable) : object 'xVariable' not found.

可能是什么问题?

服务器.R

setwd("~/csv")
shiny.maxRequestSize=30*1024^2

database <- dbConnect(MySQL(), user='user', password='', dbname='database', host='host')
dbResultSet <- dbSendQuery(database, "select * from core") #Query database for information
core<- fetch(dbResultSet, n=-1) #fetch resultset into a data frame
on.exit(dbDisconnect(database)) #Safely close database connection on application close
shinyServer(function(input, output) {


output$graphData <- renderUI({
selectInput("dataset", "Choose a dataset:" ,choices = c("pneumonia","core"))

})

#defining the xVariables for plotting
#Create variables to be used for graphing based on the data entered
#datasetInput <- dataset

output$xVariable <- renderUI({
#Initializes the variable
selectInput("xVariable","X Variable",names(graphData))
})
)


graphType<- renderText({ as.character(input$graphType) }) #graph type
graphSecondary<- renderText({ as.character(input$graphTypeSecondary) }) #graph type
xAxis <- reactive ({ input$xVariable })
yAxis <- reactive ({ input$yVariable })
xTitle <- renderText ({ as.character(input$xLabel ) })
yTitle <- renderText ({ as.character(input$yLabel ) })
legend <- renderText ({ as.character(input$legendTitle) })#graph legend
#xVar <- as.factor(xVariable)
# yVar <- as.factor(yVariable)



output$plot <- renderPlot({
pneumonia.df<- data.frame(pneumonia)
c <- ggplot(core, aes(x=na.omit (xVariable) ,fill=xVariable))
plot <- c + geom_bar() + xlab(xTitle())+ylab(yTitle())
# hist(as.numeric(core.df$nresprate))
print(plot)
})
})

ui.R

shinyUI(pageWithSidebar(
# Application title.
headerPanel("Core - Database"),

sidebarPanel(
#plotting data sidebar panel
conditionalPanel(
"$('li.active a').last().html()==='Graphs'",
HTML("<div class='span6'>"),
h4("Primary Plot"),
tags$hr(),
# selectInput("dataset", "Choose a dataset:" ,choices = c("pneumonia","core")),
htmlOutput("graphData"),
selectInput("graphType", "Choose graph to plot:",
list("Please Select a Graph" = "default",
"Histogram" = "hist",
"Box Plot" = "box",
"Scatter Plot" = "scatter"
)),
htmlOutput("xVariable"),
textInput("xLabel","X Label"),
htmlOutput("yVariable"),
textInput("yLabel","Y Label"),
textInput("legendTitle","Legend Title"),
helpText("Note: The graph only shows the data count only and scatter plots"),submitButton("Execute"),
HTML("</div>")),
mainPanel(
tabsetPanel(
tabPanel("Graphs",h4("Plot"),h4("Available Data"), plotOutput("plot"))
)
)

最佳答案

renderPlot 命令中,您引用 fillna.omit 选项中的 xVariable。您应该将其命名为 input$xVariable

编辑

根据注释中的错误消息,您需要检查代码的 react 性。在 renderPlot 部分中,您有 cplot 用作名称来保存基于 react 数据的绘图。我有两个建议:

1) 重命名这些:cplot 已经是 R 函数的名称,使用这些作为图形的名称可能会导致意想不到的后果。

2) 您需要在使这两个事物使用 react 性数据的行周围添加 reactive ({}) 包装器,并且您希望它们随着输入的变化而变化。

关于mysql - 从 Shiny 的 renderUI 中获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20494866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com