说实话,我真的不知道我在做什么,我想通过下拉菜单将数据集读入闪亮的页面,但是代码告诉我数据框不存在。 UI是正确的,因为它可与空白服务器功能一起使用。我只是试图读取两个不同的文件,它们是delim by,另一个是空格。原始代码无法在任何交互模式下工作,因此我知道该部分是正确的。 我现在已经大量更新了一些事情,似乎是这些警告和错误,我不确定如何解释它们。
编辑后添加:经过大量编辑并询问另一个论坛之后,我能够得到我所需要的答案,我想我可以分享它,以防其他人需要它。
library(stringr)
library(dplyr)
library(ggplot2)
library(zoo)
library(tokenizers)
ui <-fluidPage(
titlePanel (title= h1("Display of the Data Set vs LTSpice Simulation")),
sidebarLayout(
sidebarPanel(
selectInput( inputId = "selectDataset1", label= "1. Choose a DataSet for analysis:", choices = ""),
selectInput( inputId = "selectDataset2", label= "2. Choose Pulser Dataset for analysis:", choices = ""),
sliderInput("timeOffset", "TimeOffset", min=-500, max= 500,
value = 0, step = 100),
# Input: Specification of range within an interval ----
sliderInput("range", "Range:",
min = 1, max = 1000,
value = c(200,500))
),
mainPanel(
plotOutput ("myPlot"),
plotOutput ("myTable")
)
)
)
server<-function(input, output, session)({ #beginning of server
datasets1 <- list.files("D:/Pulserdataset/Dataset1" , pattern=".txt")
# You can use list.files() function to actually get the names of all files in a (sub)folder, and filter for .txt
# datasets1 <- list.files(pattern = ".txt")
datasets2 <- list.files("D:/Pulserdataset/LTspice/" , pattern=".txt")
#Use updateSelectInput input to update names on the go (better than defining on top)
updateSelectInput(session, "selectDataset1", choices = datasets1)
updateSelectInput(session, "selectDataset2", choices = datasets2)
DS = reactive({
#read.delim assumes the files are in the app (sub)folder (must be for Shiny to work properly)
myFile = read.delim(file=paste(input$selectDataset1, ".txt", sep = ""))
colnames(myFile) = c("Time", "Channel1_Voltage","Channel2_Voltage")
myFile
})
Pulserfile = reactive({
myFile = read.delim(file=paste(input$selectDataset2, ".txt", sep = ""))
colnames(myFile) = c("Time", "Voltage")
myFile
})
DS()[1:3,]=
output$myPlot = renderPlot({
ggplot() +
geom_line(data=DS(), aes(x=Time, y=Channel2_Voltage, colour="Data Average"), na.rm = TRUE)+
geom_line(data=Pulserfile(), aes(x=time_ns, y= Voltage , colour= "LTspice Simulation"))+
labs(
title =( paste( "vs. Ltspice simulation")),
# subtitle= (" vs. LTspice simulation "),
x = "Time (ns)",
y = 'Voltage',
colour = "Output")
})
output$myTable1 = renderTable({
DS()[1:3,] #To call a reactive dataframe, put () behind the name, but treat the rest of the code as usual
})
output$myTable2 = renderTable({
Pulserfile()[1:2,]
})
}) # end of server function
shinyApp(ui,server)
~~~~~~~~