我正在寻找一种方法来增加plotly在R.
我搜索了很多,但似乎无法找到不需要我手动定义悬停文本的方法。也许我在layout()函数中遗漏了一些东西......
一些可能导致解决方法的背景信息:我试图将百分比信息显示为十进制数,但需要比仅 0.01 (=1%) 更精确。问题是悬停文本显示相同的值 0.01,例如 0.008 和 0.012,这在图表上显然不相同。
任何帮助将非常感激!
我希望能够做类似这个答案的事情,但不使用闪亮的。我还想绑定打开与数据点关联的超链接的 onclick 事件。
我正在使用saveWidget函数 fromhtmlwidgets并且知道我可以使用
包中的appendContent函数插入 javascript 代码htmltools。
这是一个小示例代码:
library(ggplot2)
library(plotly)
library(htmlwidgets)
library(htmltools)
path.test.results <- "C:\\Users\\img\\"
myData <- data.frame(x=c(1,2,3), y=c(3,2,1))
myLinks <- c("https://www.google.com/", "https://stackoverflow.com/", "https://www.r-project.org/")
ggp <- ggplot(data=myData, aes(x=x, y=y)) + geom_point()
ply <- plotly_build(ggp)
ply$elementId <- "PlotlyGraph"
#javascript <- HTML('<script>document.getElementById("htmlwidget_container").innerHTML = "test";</script>')
javascript <- HTML(paste(
paste('<button type="button" onclick="document.getElementById(',"'", 'PlotlyGraph', "'", ').style.display=',
"'", 'none', "'", '">Hide Plot</button>', sep=''),
paste('<button type="button" onclick="document.getElementById(',"'", 'PlotlyGraph', "'", ').style.display=',
"'", 'block', "'", '">Show …Run Code Online (Sandbox Code Playgroud) 当我尝试执行下面的代码时,mariadb.ProgrammingError: Cursor is closed即使数据已成功写入数据库,python 也会给我一个 。我猜想返回行计数有问题(请参阅下面的完整回溯)。这是一个可能的错误还是我错过了什么?
代码示例
import pandas as pd
from sqlalchemy import create_engine
conn_str = 'mariadb+mariadbconnector://user:password@localhost:3306/database_name'
engine = create_engine(conn_str)
df = pd.DataFrame(data={'col1': [1, 2, 3], 'col2': ['A', 'B', 'C']})
df.to_sql('pandas_test_table', index=False, con=engine, if_exists='replace')
Run Code Online (Sandbox Code Playgroud)
追溯
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\pandas\core\generic.py", line 2951, in to_sql
return sql.to_sql(
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\pandas\io\sql.py", line 697, in to_sql
return pandas_sql.to_sql(
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\pandas\io\sql.py", line 1739, in to_sql …Run Code Online (Sandbox Code Playgroud) plotly ×2
r ×2
ggplot2 ×1
htmlwidgets ×1
hyperlink ×1
javascript ×1
mariadb ×1
pandas ×1
python ×1
sqlalchemy ×1