我有一个Shiny downloadHandler
在server.R中:
output$DownloadButton <- downloadHandler(
filename = function() {
paste("test", Sys.Date(), ".csv",sep="")
},
content = function(con) {
print("in download")
print(con) # this prints C:\\Users\\me\\Local\\Temp\\RtmpI1EjY7\\file668338e4c33
Data<-ReactiveGetData()$Data #Here I get the data I want to download
print(head(Data)) #This prints out the data with no errors
write.csv(Data, con)
}
)
Run Code Online (Sandbox Code Playgroud)
这是ui.r:
sidebarPanel(
downloadButton("DownloadButton", label = "Download",class = NULL), ....
Run Code Online (Sandbox Code Playgroud)
到目前为止它打印了临时文件:
C:\\Users\\me\\Local\\Temp\\RtmpI1EjY7\\file668338e4c33
Run Code Online (Sandbox Code Playgroud)
但是当我手动转到此路径时,我收到错误消息"找不到文件"
然后当我点击下载按钮时,我没有收到错误,也没有任何反应.
知道为什么临时文件似乎没有被创建?
临时文件应该以csv结尾吗?
这里是一个简单的简单例子,如果你运行server.r和ui.r文件,你可以运行它.我无法下载以下文件:
任何想法下面都不存在"文件"对象为什么?
ui.r
library(shiny)
shinyUI(fluidPage(
sidebarPanel(
downloadButton("Download", label = "Download",class = NULL)
),
mainPanel( …Run Code Online (Sandbox Code Playgroud) 我有一个包含许多情节的Shiny Web应用程序。每个图都有自己的SQL查询来获取数据。查询之一可能返回一个数据不足的表。如果发生这种情况,那么我想在绘图所在的选项卡中显示一条文本消息。
server.R:
library(shiny)
library(RMySQL)
shinyServer(function(input, output, session) {
output$lineGraphOne <- renderPlot({
table <- getDataSomeHowOne()
if(dim(table[1]) < 3) {
error <- paste("Some error message")
} else {
plot(x = as.Date(table$date), y = table$count)
}
})
output$lineGraphTwo <- renderPlot({
table <- getDataSomeHowTwo()
if(dim(table[1]) < 3) {
error <- paste("Some error message")
} else {
plot(x = as.Date(table$date), y = table$count)
}
})
})
Run Code Online (Sandbox Code Playgroud)
用户界面
library(shiny)
shinyUI(navbarPage("Title",
tabPanel("Name",
sidebarLayout(
mainPanel(
tabsetPanel(id = "tabs",
tabPanel("One", plotOutput("lineGraphOne")),
tabPanel("Two", plotOutput("lineGraphTwo"))
)
),
sidebarPanel(
dateInput('queryDate', 'Datum:', …Run Code Online (Sandbox Code Playgroud) 我想删除第二列 = 0 的 Pandas 数据框中的行
所以这 ...
Code Int
0 A 0
1 A 1
2 B 1
Run Code Online (Sandbox Code Playgroud)
会变成这样...
Code Int
0 A 1
1 B 1
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助!
我正在尝试用 Python 连接到雪花。目前我还没有成功。我读过有关使用引擎方式的论坛,即:
url = URL(
account = 'xxxx',
user = 'xxxx',
password = 'xxxx',
database = 'xxx',
schema = 'xxxx',
warehouse = 'xxx',
role='xxxxx',
authenticator='https://xxxxx.okta.com',
)
engine = create_engine(url)
connection = engine.connect()
query = '''
select * from MYDB.MYSCHEMA.MYTABLE
LIMIT 10;
'''
df = pd.read_sql(query, connection)
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
ModuleNotFoundError: No module named 'snowflake.sqlalchemy'
Run Code Online (Sandbox Code Playgroud)
如何在 Anaconda 中安装此模块?我找不到如何解决这个问题,我读过的任何其他方式都行不通。
我知道有一些关于这个问题的帖子,但我不知道为什么我的代码不起作用.我有一个Shiny的应用程序,我希望包含一个条件侧边栏面板,根据用户当前选择的主面板中的哪个面板显示不同的控件.我认为下面的代码可以工作,但应用程序只显示条件面板1(定义如下).任何人都可以给我任何建议吗?谢谢.
我的ui.R:
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel("Spatially Balanced Sampling Tool"),
sidebarPanel(
tags$head(
tags$style(type="text/css", "select { max-width: 175px; }"),
tags$style(type="text/css", "textarea { max-width: 100px; }"),
tags$style(type="text/css", ".jslider { max-width: 120px; }"),
tags$style(type='text/css', ".well { max-width: 200px; }"),
tags$style(type='text/css', ".span4 { max-width: 200px; }")
),
conditionalPanel(condition="input.conditionedPanels == 1",
fileInput('file1', 'Choose .ZIP Shapefile:', multiple=TRUE,
accept=c('binary'))
),
conditionalPanel(condition="input.conditionedPanels == 2",
numericInput("pts", "# of sampling points per stratum:", 50),
numericInput("oversamppts", "# to OVER sample (optional):", 5),
submitButton("Generate Points"),
helpText("WORK DAMMIT")
)),
mainPanel(
tabsetPanel(
tabPanel("Instructions", …Run Code Online (Sandbox Code Playgroud) 新的并坚持使用 ggplot:
我有以下数据:
tribe rho preference_watermass
1 Luna2 -1.000 hypolimnic
2 OP10I-A1 -1.000 epilimnic
3 B0_FO56C -0.986 hypolimnic
4 Planctomycetes_FGIDN -0.943 hypolimnic
5 acIV_IVNEG -0.943 hypolimnic
6 FTD4J6C01EE04F -0.941 hypolimnic
7 alll -0.941 hypolimnic
8 FTD4J6C02HMHDM -0.928 hypolimnic
9 Planctomycetes_GQLBU -0.928 hypolimnic
10 acII-A -0.886 epilimnic
11 LD19_GMKGQ -0.880 hypolimnic
12 acIV_E2W4O -0.880 hypolimnic
13 Planctomycetes_AFE3Z -0.880 epilimnic
14 Bacteriodetes -0.880 epilimnic
15 FTD4J6C01APQD0 -0.880 epilimnic
16 FTD4J6C02GBAUX -0.880 epilimnic
17 baII -0.845 epilimnic
18 FTD4J6C01CJCBG 0.812 transitient
19 Pyxis …Run Code Online (Sandbox Code Playgroud) 我有10支队伍,我想举办一个活动,让他们在比赛中一战。
我可以在 Excel 或 R 中执行此操作吗?
我有这个JSON数据:
var lists = [{
"listId": 1,
"permission": "WRITE"
}, {
"listId": 2,
"permission": "WRITE"
}, {
"listId": 2,
"permission": "READ"
}, {
"listId": 3,
"permission": "READ"
}, {
"listId": 3,
"permission": "WRITE"
}, {
"listId": 5,
"permission": "WRITE"
}]
Run Code Online (Sandbox Code Playgroud)
还有这个:
var arr = [{
"listId": 1,
"confidentiality": "PUBLIC",
"listName": "List name here..1",
"permission": "WRITE"
}, {
"listId": 2,
"confidentiality": "PUBLIC",
"listName": "List name here..2",
"permission": "READ"
}, {
"listId": 3,
"confidentiality": "CONFIDENTIAL",
"listName": "List name here..3",
"permission": "WRITE"
}, …Run Code Online (Sandbox Code Playgroud) 我有一个嵌套列表,我想使用 R 将其转换为数据框,类似于此问题flatten a dataframe
这是我的列表的结构
> str(rf_curves$GBP)
List of 27
$ NA :'data.frame': 0 obs. of 2 variables:
..$ date :Class 'Date' int(0)
..$ px_last: num(0)
$ BP0012M Index :'data.frame': 5 obs. of 2 variables:
..$ date : Date[1:5], format: "2018-05-21" "2018-05-22" ...
..$ px_last: num [1:5] 0.929 0.931 0.918 0.918 0.901
$ BP0003M Index :'data.frame': 5 obs. of 2 variables:
..$ date : Date[1:5], format: "2018-05-21" "2018-05-22" ...
..$ px_last: num [1:5] 0.623 0.623 0.619 0.614 0.611 …Run Code Online (Sandbox Code Playgroud) 我在ggplot2 3.0.0中使用plotly 4.8,并尝试向散点图添加文本标签并使其对齐。但是,似乎该hjust参数已被忽略geom_text(aes(....), hjust = "left")。(也尝试过hjust = 0。)
GGPLOT输出
看到它在绘图窗口中以ggplot对齐,标签保持对齐。
全面输出
但是,对齐方式在转换中丢失,并且文本居中。
因此,问题是,是否有可能通过情节修复这种对齐方式?
测试示例代码
library(ggplot2)
library(data.table)
library(plotly)
data(mtcars)
plotdata <- as.data.table(mtcars)
plotdata$carname <- rownames(mtcars)
# take a small demo subset
plotdata <- plotdata[1:10,]
gg <- ggplot(plotdata, aes(x = wt, y = mpg, label = carname)) +
geom_point() + theme_minimal()
gg <- gg + geom_text(aes(label = carname),
size = 2,
hjust = "left")
print(gg)
# convert ggplot
p <- ggplotly(gg)
p
Run Code Online (Sandbox Code Playgroud)