gpt4 book ai didi

r - Shiny 快速显示选定的输入,但恢复为第一个输入

转载 作者:行者123 更新时间:2023-12-01 07:57:15 29 4
gpt4 key购买 nike

一切加载正常,但每当我选择 Watts、Volts 或 Amps 时,Dygraph 图表会迅速恢复为绘制扫描 channel 。瓦数、电压和安培图表会快速显示,但随后会恢复为扫描输入。

关于如何让它停止恢复到扫描 channel 并将其保留在我选择的 channel 上的任何想法?

My dataset is here for you to upload.ui.R

shinyUI(fluidPage(
navbarPage("Engineering Data",
tabPanel("Upload your Own File:",
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
tags$hr(),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
','),
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"'),
selectInput("uploadChannels", label = "Choose Channel",
choices = NULL)
),
mainPanel(
dygraphOutput('graph')
))



)

)))

服务器.R

output$graph <- renderDygraph({
uploadedFile <- input$file1

if (is.null(uploadedFile))
return(NULL)

# Clean up the loaded CSV File, convert Time column to a Time Object for Dygraph.
uploadedFile <- read.csv(uploadedFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
uploadedFile$Time <- as.POSIXct(strptime(uploadedFile$Time,"%H:%M:%S"))
uploadedFile$ctime <- strptime(paste(uploadedFile$Time), "%Y-%m-%d %H:%M:%S")

# Update the SelectInput and store the value in component5 to be used in the graph.

observeEvent(uploadedFile, {
updateSelectizeInput(session, 'uploadChannels', choices = names(uploadedFile))
})
selectedInput <- input$uploadChannels
component5 <- uploadedFile[, selectedInput]


xts(component5, uploadedFile$Time) %>%
dygraph()
})

})

最佳答案

@Batanichek 是正确的。我不得不修改 server.R,它现在可以工作了!
请注意,我添加了第二个输入,这就是命令加倍的原因。

  uploadedFile1 <- reactive({
validate(need(input$file1, FALSE)) # This is like a better "if (is.null(input$file1)) return(NULL)"
uf1 <- read.csv(input$file1$datapath)
})
uploadedFile2 <- reactive({
validate(need(input$file2, FALSE)) # This is like a better "if (is.null(input$file2)) return(NULL)"
uf2 <- read.csv(input$file2$datapath)
})

observeEvent(uploadedFile1(), {
updateSelectizeInput(session, 'uploadChannels1', choices = names(uploadedFile1()))
})
observeEvent(uploadedFile2(), {
updateSelectizeInput(session, 'uploadChannels2', choices = names(uploadedFile2()))
})

output$graph <- renderDygraph({


# Clean up the loaded CSV File, convert Time column to a Time Object for Dygraph.
uploadedFile1 <- uploadedFile1()
uploadedFile2 <- uploadedFile2()

uploadedFile1$Time <- as.POSIXct(strptime(uploadedFile1$Time,"%H:%M:%S"))
uploadedFile2$Time <- as.POSIXct(strptime(uploadedFile2$Time,"%H:%M:%S"))

uploadedFile1$ctime <- strptime(paste(uploadedFile1$Time), "%Y-%m-%d %H:%M:%S")
uploadedFile2$ctime <- strptime(paste(uploadedFile2$Time), "%Y-%m-%d %H:%M:%S")

# Update the SelectInput and store the value in component5 to be used in the graph.
selectedInput1 <- input$uploadChannels1
selectedInput2 <- input$uploadChannels2
component5 <- uploadedFile1[, selectedInput1]
component6 <- uploadedFile2[, selectedInput2]
cbinded <- cbind(component5, component6)

xts(cbinded, uploadedFile1$Time, uploadedFile2$Time) %>%
dygraph()

})

关于r - Shiny 快速显示选定的输入,但恢复为第一个输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34341316/

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