Popular New Releases in JSON Processing
json
JSON for Modern C++ version 3.10.5
fastjson
fastjson 1.2.79版本发布,BUG修复
gson
Gson 2.9.0
normalizr
v3.6.1
lowdb
Popular Libraries in JSON Processing
by nlohmann c++
29628 MIT
JSON for Modern C++
by alibaba java
24265 Apache-2.0
A fast JSON parser/generator for Java.
by stedolan c
20842 NOASSERTION
Command-line JSON processor
by google java
20811 Apache-2.0
A Java serialization/deserialization library to convert Java Objects into JSON and back
by paularmstrong javascript
20808 MIT
Normalizes nested JSON according to a schema
by SwiftyJSON swift
20691 MIT
The better way to deal with JSON data in Swift.
by typicode javascript
16199 NOASSERTION
Local JSON database for small projects (supports Node, Electron and the browser)
by modood javascript
11900 WTFPL
中华人民共和国行政区划:省级(省份直辖市自治区)、 地级(城市)、 县级(区县)、 乡级(乡镇街道)、 村级(村委会居委会) ,中国省市区镇村二级三级四级五级联动地址数据。
by Tencent c++
11703 NOASSERTION
A fast JSON parser/generator for C++ with both SAX/DOM style API
Trending New libraries in JSON Processing
by TomWright go
3063 MIT
Select, put and delete data from JSON, TOML, YAML, XML and CSV files with a single tool. Supports conversion between formats and can be used as a Go package.
by cue-lang go
2321 Apache-2.0
The new home of the CUE language! Validate and define text-based and dynamic configuration
by trailofbits python
2003 LGPL-3.0
A semantic diff utility and library for tree-like files such as JSON, JSON5, XML, HTML, YAML, and CSV.
by ibireme c
1867 MIT
The fastest JSON library in C
by alex html
1782 MIT
by multiprocessio typescript
1467 NOASSERTION
App to easily query, script, and visualize data from every database, file, and API.
by goccy go
1294 MIT
Fast JSON encoder/decoder compatible with encoding/json for Go
by minio go
1273 Apache-2.0
Golang port of simdjson: parsing gigabytes of JSON per second
by cisagov python
976 CC0-1.0
A DFIR tool written in Python.
Top Authors in JSON Processing
1
20 Libraries
189
2
20 Libraries
2886
3
18 Libraries
7175
4
18 Libraries
25916
5
15 Libraries
868
6
14 Libraries
625
7
13 Libraries
152
8
12 Libraries
2172
9
12 Libraries
117
10
11 Libraries
44
1
20 Libraries
189
2
20 Libraries
2886
3
18 Libraries
7175
4
18 Libraries
25916
5
15 Libraries
868
6
14 Libraries
625
7
13 Libraries
152
8
12 Libraries
2172
9
12 Libraries
117
10
11 Libraries
44
Trending Kits in JSON Processing
An ordered list of values is called a JSON array. It can store multiple values, strings, numbers, booleans, or objects in a JSON array. A comma must separate the values in the JSON array. A normal text file or stored data in column by column and split by a comma is called a CSV(comma-separated values).
Now will see the procedure to convert the JSON array to CSV,
- Read the data from the JSON file and store the result as a string.
- Construct a JSON object using the above string.
- Get the JSON Array from the JSON Object.
- Create a new CSV file using java. io. File.
- Deliver a comma-delimited text from the JSONArray of JSONObjects and write it to the newly created CSV file.
The JSON can be used as a 'data-interchange format' and it is 'lightweight' and 'language independent'. It can parse text from a string to produce vector-like objects. The advantage of using JSON for data storage, it is safe for transferring the data and suitable across platforms. To store the data comparatively JSON is preferred better than CSV In terms of scalability of application or file and while working with a large volume of data. The most common usage of JSON is used in JavaScript-based applications that have browser extensions and websites as a part of their features.
Here is an example of how you can convert JSON array to CSV in Java:
Fig 1: Preview of the output that you will get on running this code from your IDE
Code
Instructions
- Copy the code using the "Copy" button above, and paste it in a Java file in your IDE.
- Add the required dependencies and import them in java file.
- Run the file to generate the output csv file.
I hope you found this useful. I have added the link to dependent libraries, version information in the following sections.
I found this code snippet by searching for 'json array list to csv format' in kandi. You can try any such use case!
Environment Tested
I tested this solution in the following versions. Be mindful of changes when working with other versions.
- The solution is created in Java 11.0.17.
- The solution is tested on JSON Version:20210307 and apache.commons:commons-io:1.3.2.
Using this solution, we are able to convert an json array to csv with simple steps. This process also facilities an easy way to use, hassle-free method to create a hands-on working version of code which would help us to convert an json array to csv.
Dependent Libraries
You can add the dependent library in your gradle or maven files. you can get the dependancy xml in above link
You can search for any dependent library on kandi like apache commons io and json java
Support
- For any support on kandi solution kits, please use the chat
- For further learning resources, visit the Open Weaver Community learning page.
Trending Discussions on JSON Processing
st_read path for shinyapp in R
How to write jsonb inside WHERE without JSON Processing Functions
Renumerating indexed JSON
How to get values from array of JSON in C#
SSIS Script Task Fails with NewtonSoft.Json
Is there an automated way to split a JSON(B) column into multiple columns in PostgreSQL?
Register Java Class in Flink Cluster
A simple way to parse XML with repeated element using Jackson
Shiny.io cannot deploy the application
How to deploy shiny app to shinyapps.io from drake plan
QUESTION
st_read path for shinyapp in R
Asked 2021-Oct-03 at 00:33Usually when st_read
is used you put path in dsn
, but in case of shiny if you put a full path inside dsn
it will give an error as that file path does not exist on the server. So, now I put the shapefile in the www
folder, but I don't know what path to put in dsn
so that the app picks up the shapefile.
How can I fix this?
Current function code in the app:
1rocks_utm_sf = st_read(dsn = "D:/Sedimentary_Data_Analysis/www",layer = "Sed_UTM")
2
Below error in the log breaks the app
1rocks_utm_sf = st_read(dsn = "D:/Sedimentary_Data_Analysis/www",layer = "Sed_UTM")
2 021-10-02T19:05:08.733697+00:00 shinyapps[4783188]: Server version: 1.8.6.1
32021-10-02T19:05:08.733707+00:00 shinyapps[4783188]: R version: 4.0.2
42021-10-02T19:05:08.733705+00:00 shinyapps[4783188]: LANG: en_US.UTF-8
52021-10-02T19:05:08.725767+00:00 shinyapps[4783188]: Running on host: 52b53ce9aed0
62021-10-02T19:05:08.733716+00:00 shinyapps[4783188]: shiny version: 1.6.0
72021-10-02T19:05:08.733732+00:00 shinyapps[4783188]: httpuv version: 1.6.1
82021-10-02T19:05:08.931183+00:00 shinyapps[4783188]: Using jsonlite for JSON processing
92021-10-02T19:05:08.934357+00:00 shinyapps[4783188]:
102021-10-02T19:05:08.733977+00:00 shinyapps[4783188]: Using pandoc: /opt/connect/ext/pandoc/2.11
112021-10-02T19:05:08.733739+00:00 shinyapps[4783188]: rmarkdown version: 2.9
122021-10-02T19:05:08.733790+00:00 shinyapps[4783188]: jsonlite version: 1.7.2
132021-10-02T19:05:08.934357+00:00 shinyapps[4783188]: Starting R with process ID: '26'
142021-10-02T19:05:08.733779+00:00 shinyapps[4783188]: knitr version: 1.33
152021-10-02T19:05:08.963216+00:00 shinyapps[4783188]:
162021-10-02T19:05:08.733791+00:00 shinyapps[4783188]: RJSONIO version: (none)
172021-10-02T19:05:08.733797+00:00 shinyapps[4783188]: htmltools version: 0.5.1.1
182021-10-02T19:05:08.963841+00:00 shinyapps[4783188]: box
192021-10-02T19:05:08.963217+00:00 shinyapps[4783188]:
202021-10-02T19:05:08.963840+00:00 shinyapps[4783188]: The following object is masked from ‘package:graphics’:
212021-10-02T19:05:08.963840+00:00 shinyapps[4783188]:
222021-10-02T19:05:08.963217+00:00 shinyapps[4783188]: Attaching package: ‘shinydashboard’
232021-10-02T19:05:08.963841+00:00 shinyapps[4783188]:
242021-10-02T19:05:10.008023+00:00 shinyapps[4783188]: ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
252021-10-02T19:05:10.013142+00:00 shinyapps[4783188]: ✔ ggplot2 3.3.5 ✔ purrr 0.3.4
262021-10-02T19:05:10.013143+00:00 shinyapps[4783188]: ✔ tibble 3.1.3 ✔ dplyr 1.0.7
272021-10-02T19:05:10.013144+00:00 shinyapps[4783188]: ✔ tidyr 1.1.3 ✔ stringr 1.4.0
282021-10-02T19:05:10.194146+00:00 shinyapps[4783188]: ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
292021-10-02T19:05:10.194148+00:00 shinyapps[4783188]: ✖ dplyr::lag() masks stats::lag()
302021-10-02T19:05:10.013144+00:00 shinyapps[4783188]: ✔ readr 2.0.0 ✔ forcats 0.5.1
312021-10-02T19:05:10.194148+00:00 shinyapps[4783188]: ✖ dplyr::filter() masks stats::filter()
322021-10-02T19:05:10.415161+00:00 shinyapps[4783188]: Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
332021-10-02T19:05:10.464817+00:00 shinyapps[4783188]: Listening on http://127.0.0.1:44842
342021-10-02T19:05:10.464815+00:00 shinyapps[4783188]:
352021-10-02T19:05:16.625537+00:00 shinyapps[4783188]: Warning: Error in : Cannot open "D:/Sedimentary_Data_Analysis/www"; The file doesn't seem to exist.
362021-10-02T19:05:16.630916+00:00 shinyapps[4783188]: 113: <Anonymous>
37
ANSWER
Answered 2021-Oct-03 at 00:33Thanks to Guillaumme for his comment, so I was able to fix the problem by first moving the shiny
app to a R
project. Then in the app
code write st_read
as follows, and the app is able to pick up the shapefile when its published on shinyapps.io
.
1rocks_utm_sf = st_read(dsn = "D:/Sedimentary_Data_Analysis/www",layer = "Sed_UTM")
2 021-10-02T19:05:08.733697+00:00 shinyapps[4783188]: Server version: 1.8.6.1
32021-10-02T19:05:08.733707+00:00 shinyapps[4783188]: R version: 4.0.2
42021-10-02T19:05:08.733705+00:00 shinyapps[4783188]: LANG: en_US.UTF-8
52021-10-02T19:05:08.725767+00:00 shinyapps[4783188]: Running on host: 52b53ce9aed0
62021-10-02T19:05:08.733716+00:00 shinyapps[4783188]: shiny version: 1.6.0
72021-10-02T19:05:08.733732+00:00 shinyapps[4783188]: httpuv version: 1.6.1
82021-10-02T19:05:08.931183+00:00 shinyapps[4783188]: Using jsonlite for JSON processing
92021-10-02T19:05:08.934357+00:00 shinyapps[4783188]:
102021-10-02T19:05:08.733977+00:00 shinyapps[4783188]: Using pandoc: /opt/connect/ext/pandoc/2.11
112021-10-02T19:05:08.733739+00:00 shinyapps[4783188]: rmarkdown version: 2.9
122021-10-02T19:05:08.733790+00:00 shinyapps[4783188]: jsonlite version: 1.7.2
132021-10-02T19:05:08.934357+00:00 shinyapps[4783188]: Starting R with process ID: '26'
142021-10-02T19:05:08.733779+00:00 shinyapps[4783188]: knitr version: 1.33
152021-10-02T19:05:08.963216+00:00 shinyapps[4783188]:
162021-10-02T19:05:08.733791+00:00 shinyapps[4783188]: RJSONIO version: (none)
172021-10-02T19:05:08.733797+00:00 shinyapps[4783188]: htmltools version: 0.5.1.1
182021-10-02T19:05:08.963841+00:00 shinyapps[4783188]: box
192021-10-02T19:05:08.963217+00:00 shinyapps[4783188]:
202021-10-02T19:05:08.963840+00:00 shinyapps[4783188]: The following object is masked from ‘package:graphics’:
212021-10-02T19:05:08.963840+00:00 shinyapps[4783188]:
222021-10-02T19:05:08.963217+00:00 shinyapps[4783188]: Attaching package: ‘shinydashboard’
232021-10-02T19:05:08.963841+00:00 shinyapps[4783188]:
242021-10-02T19:05:10.008023+00:00 shinyapps[4783188]: ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
252021-10-02T19:05:10.013142+00:00 shinyapps[4783188]: ✔ ggplot2 3.3.5 ✔ purrr 0.3.4
262021-10-02T19:05:10.013143+00:00 shinyapps[4783188]: ✔ tibble 3.1.3 ✔ dplyr 1.0.7
272021-10-02T19:05:10.013144+00:00 shinyapps[4783188]: ✔ tidyr 1.1.3 ✔ stringr 1.4.0
282021-10-02T19:05:10.194146+00:00 shinyapps[4783188]: ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
292021-10-02T19:05:10.194148+00:00 shinyapps[4783188]: ✖ dplyr::lag() masks stats::lag()
302021-10-02T19:05:10.013144+00:00 shinyapps[4783188]: ✔ readr 2.0.0 ✔ forcats 0.5.1
312021-10-02T19:05:10.194148+00:00 shinyapps[4783188]: ✖ dplyr::filter() masks stats::filter()
322021-10-02T19:05:10.415161+00:00 shinyapps[4783188]: Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
332021-10-02T19:05:10.464817+00:00 shinyapps[4783188]: Listening on http://127.0.0.1:44842
342021-10-02T19:05:10.464815+00:00 shinyapps[4783188]:
352021-10-02T19:05:16.625537+00:00 shinyapps[4783188]: Warning: Error in : Cannot open "D:/Sedimentary_Data_Analysis/www"; The file doesn't seem to exist.
362021-10-02T19:05:16.630916+00:00 shinyapps[4783188]: 113: <Anonymous>
37 sf_object = st_read(dsn = "www", layer = "Name")
38
QUESTION
How to write jsonb inside WHERE without JSON Processing Functions
Asked 2021-Aug-17 at 05:22This is my query
and it works. I store the list of dictionaries inside my jsonb
column.
1SELECT
2 items.title
3FROM
4 items
5WHERE
6 jsonb_path_exists(items.types::jsonb, '$[*] ? (@.target == "discount")')
7
Is there any way to write this without jsonb_path_exists()
function?
Also, do JSON Processing Functions use indexing?
I want to simplify the readability/look of my query because it is so long. And curious if I can get any performance improvements by not using JSON Processing Functions.
I tried to replace it with @?
but failed. This is what I used (quote from PostgreSQL):
jsonb @? jsonpath → boolean
Does JSON path return any item for the specified JSON value?
'{"a":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)' → t
Any help is very much appreciated.
ANSWER
Answered 2021-Aug-17 at 05:22The evaluation of the JSON path is a bit different between the jsonb_path_xxx()
functions and the equivalent operator. Most importantly you do not need the ? (...)
condition as that is implied when using the operator.
The following should be equivalent:
1SELECT
2 items.title
3FROM
4 items
5WHERE
6 jsonb_path_exists(items.types::jsonb, '$[*] ? (@.target == "discount")')
7where items.types::jsonb @? '$[*].target == "discount"'
8
If you want to simplify or shorten your query, introduce an alias for items
so that you don't need to repeat the complete table name everywhere. Converting the column types
to jsonb
would further simplify your query as you don't need the cast anymore.
And curious if I can get any performance improvements by not using JSON Processing Functions.
The @?
operator can make use of a GIN index - but this only works for jsonb
not for the json
data type.
The above where condition could make use of the following index:
1SELECT
2 items.title
3FROM
4 items
5WHERE
6 jsonb_path_exists(items.types::jsonb, '$[*] ? (@.target == "discount")')
7where items.types::jsonb @? '$[*].target == "discount"'
8create index on items using gin ( (types::jsonb) );
9
The index definition could be simplified by removing the cast, if the column was correctly defined as jsonb
.
QUESTION
Renumerating indexed JSON
Asked 2021-Jun-30 at 15:27I have data stored in a JSON - and one of the fields is an index that determines the order in which the other data is done. Imagine
1 [
2 {
3 “Action” : “Wake up”,
4 “id” : 1
5 },
6 {
7 “Action” : “Make coffee”,
8 “id” : 2
9 },
10 {
11 “Action” : “Check Email”,
12 “id” : 3
13 }
14 ]
15
Problem is that if I want to include an extra item mid-list - I am having to manually re-enter all the indices. E.g. if I decided I should insert
1 [
2 {
3 “Action” : “Wake up”,
4 “id” : 1
5 },
6 {
7 “Action” : “Make coffee”,
8 “id” : 2
9 },
10 {
11 “Action” : “Check Email”,
12 “id” : 3
13 }
14 ]
15{
16“Action” : “Feed Cat”,
17“id” : 2
18}
19
Then all the lower indices would be wrong.
Is there a tool that can automatically renumber so that the id fields were always sequential 1,2,3,4,5, however I moved around the data items?
There is an option to add a plugin script - sample is below - but I don't know JavaScript so I can't clearly see how to edit it to do the bulk edit I want
1 [
2 {
3 “Action” : “Wake up”,
4 “id” : 1
5 },
6 {
7 “Action” : “Make coffee”,
8 “id” : 2
9 },
10 {
11 “Action” : “Check Email”,
12 “id” : 3
13 }
14 ]
15{
16“Action” : “Feed Cat”,
17“id” : 2
18}
19PJEPlugIn = {
20JSON processing function, will take two arguments @param json JSON object from editor, maybe null for inform JSON @param jsonStr JSON text from editor
21@return Return value can be any valid JavaScript object, string will be treated as JSON text */
22func: function(json, jsonStr) {
23return eval('(' + jsonStr + ')');
24 }
25}
26
ANSWER
Answered 2021-Jun-30 at 15:27Use any programing language, With java script, use Array.splice
1 [
2 {
3 “Action” : “Wake up”,
4 “id” : 1
5 },
6 {
7 “Action” : “Make coffee”,
8 “id” : 2
9 },
10 {
11 “Action” : “Check Email”,
12 “id” : 3
13 }
14 ]
15{
16“Action” : “Feed Cat”,
17“id” : 2
18}
19PJEPlugIn = {
20JSON processing function, will take two arguments @param json JSON object from editor, maybe null for inform JSON @param jsonStr JSON text from editor
21@return Return value can be any valid JavaScript object, string will be treated as JSON text */
22func: function(json, jsonStr) {
23return eval('(' + jsonStr + ')');
24 }
25}
26let data = [{
27 "Action": "Wake up",
28 "id": 1
29 },
30 {
31 "Action": "Make coffee",
32 "id": 2
33 },
34 {
35 "Action": "Check Email",
36 "id": 3
37 }
38];
39let item = { "Action" : "Feed Cat", "id" : 2 }
40// with Array.splice() method
41// 1st argument is insertion index (start)
42// 2nd delete count
43// 3nd insertion item
44data.splice(1, 1, item);
45
46console.log(data)
Note: In computing, index count from 0.
QUESTION
How to get values from array of JSON in C#
Asked 2021-Jun-23 at 20:23I am new to JSON processing by NewtonSoft on C#. I have the following JSON and trying to get all orderIds and orderNumbers. I tried the following code. But in both cases, I am getting can't access child items error. I also tried using JObject.Parse(json) and tried to get the two values, but got similar errors.
1{
2 "orders": [{
3 "orderId": 123,
4 "orderNumber": "234",
5 "billTo": {
6 "name": "John1 Doe1",
7 "Street": "1 one way"
8 },
9 "items": [{
10 "orderItemId": 46429,
11 "lineItemKey": "110",
12 "sku": "Hammer",
13 "name": "Small Hammer"
14 }]
15 },
16 {
17 "orderId": 567,
18 "orderNumber": "789",
19 "billTo": {
20 "name": "John2 Doe2",
21 "Street": "2 second way"
22 },
23 "items": [{
24 "orderItemId": 76567,
25 "lineItemKey": "213",
26 "sku": "Tape",
27 "name": "Electric Tape"
28 }]
29 },
30 {
31 "orderId": 223,
32 "orderNumber": "334",
33 "billTo": {
34 "name": "John3 Doe4",
35 "Street": "3 third way"
36 },
37 "items": [{
38 "orderItemId": 87890,
39 "lineItemKey": "890",
40 "sku": "Box",
41 "name": "Wooden box"
42 }]
43 }
44 ]
45}
46
1{
2 "orders": [{
3 "orderId": 123,
4 "orderNumber": "234",
5 "billTo": {
6 "name": "John1 Doe1",
7 "Street": "1 one way"
8 },
9 "items": [{
10 "orderItemId": 46429,
11 "lineItemKey": "110",
12 "sku": "Hammer",
13 "name": "Small Hammer"
14 }]
15 },
16 {
17 "orderId": 567,
18 "orderNumber": "789",
19 "billTo": {
20 "name": "John2 Doe2",
21 "Street": "2 second way"
22 },
23 "items": [{
24 "orderItemId": 76567,
25 "lineItemKey": "213",
26 "sku": "Tape",
27 "name": "Electric Tape"
28 }]
29 },
30 {
31 "orderId": 223,
32 "orderNumber": "334",
33 "billTo": {
34 "name": "John3 Doe4",
35 "Street": "3 third way"
36 },
37 "items": [{
38 "orderItemId": 87890,
39 "lineItemKey": "890",
40 "sku": "Box",
41 "name": "Wooden box"
42 }]
43 }
44 ]
45}
46 dynamic dynJson = JsonConvert.DeserializeObject(json);
47foreach (var item in dynJson)
48{
49 //Console.WriteLine("{0} {1} \n", item["orders"].orderId,
50 item["orders"].orderNumber);
51 Console.WriteLine("{0} {1} \n", item["orders"]["orderId"], item["orders"]
52 ["orderNumber"]);
53}
54
ANSWER
Answered 2021-Jun-23 at 19:49The for
loop statement seems to be wrong since dynJson
is an object and not an array. You need to loop through the dynJson.orders, like below.
1{
2 "orders": [{
3 "orderId": 123,
4 "orderNumber": "234",
5 "billTo": {
6 "name": "John1 Doe1",
7 "Street": "1 one way"
8 },
9 "items": [{
10 "orderItemId": 46429,
11 "lineItemKey": "110",
12 "sku": "Hammer",
13 "name": "Small Hammer"
14 }]
15 },
16 {
17 "orderId": 567,
18 "orderNumber": "789",
19 "billTo": {
20 "name": "John2 Doe2",
21 "Street": "2 second way"
22 },
23 "items": [{
24 "orderItemId": 76567,
25 "lineItemKey": "213",
26 "sku": "Tape",
27 "name": "Electric Tape"
28 }]
29 },
30 {
31 "orderId": 223,
32 "orderNumber": "334",
33 "billTo": {
34 "name": "John3 Doe4",
35 "Street": "3 third way"
36 },
37 "items": [{
38 "orderItemId": 87890,
39 "lineItemKey": "890",
40 "sku": "Box",
41 "name": "Wooden box"
42 }]
43 }
44 ]
45}
46 dynamic dynJson = JsonConvert.DeserializeObject(json);
47foreach (var item in dynJson)
48{
49 //Console.WriteLine("{0} {1} \n", item["orders"].orderId,
50 item["orders"].orderNumber);
51 Console.WriteLine("{0} {1} \n", item["orders"]["orderId"], item["orders"]
52 ["orderNumber"]);
53}
54dynamic dynJson = JsonConvert.DeserializeObject(data);
55 foreach (var item in dynJson.orders)
56 {
57 //Console.WriteLine("{0} {1} \n", item["orders"].orderId,
58 //item["orders"].orderNumber);
59 Console.WriteLine("{0} {1} \n", item.orderId,
60 item.orderNumber);
61 }
62}
63
Above code will print out
1{
2 "orders": [{
3 "orderId": 123,
4 "orderNumber": "234",
5 "billTo": {
6 "name": "John1 Doe1",
7 "Street": "1 one way"
8 },
9 "items": [{
10 "orderItemId": 46429,
11 "lineItemKey": "110",
12 "sku": "Hammer",
13 "name": "Small Hammer"
14 }]
15 },
16 {
17 "orderId": 567,
18 "orderNumber": "789",
19 "billTo": {
20 "name": "John2 Doe2",
21 "Street": "2 second way"
22 },
23 "items": [{
24 "orderItemId": 76567,
25 "lineItemKey": "213",
26 "sku": "Tape",
27 "name": "Electric Tape"
28 }]
29 },
30 {
31 "orderId": 223,
32 "orderNumber": "334",
33 "billTo": {
34 "name": "John3 Doe4",
35 "Street": "3 third way"
36 },
37 "items": [{
38 "orderItemId": 87890,
39 "lineItemKey": "890",
40 "sku": "Box",
41 "name": "Wooden box"
42 }]
43 }
44 ]
45}
46 dynamic dynJson = JsonConvert.DeserializeObject(json);
47foreach (var item in dynJson)
48{
49 //Console.WriteLine("{0} {1} \n", item["orders"].orderId,
50 item["orders"].orderNumber);
51 Console.WriteLine("{0} {1} \n", item["orders"]["orderId"], item["orders"]
52 ["orderNumber"]);
53}
54dynamic dynJson = JsonConvert.DeserializeObject(data);
55 foreach (var item in dynJson.orders)
56 {
57 //Console.WriteLine("{0} {1} \n", item["orders"].orderId,
58 //item["orders"].orderNumber);
59 Console.WriteLine("{0} {1} \n", item.orderId,
60 item.orderNumber);
61 }
62}
63123 234
64567 789
65223 334
66
QUESTION
SSIS Script Task Fails with NewtonSoft.Json
Asked 2021-Jan-26 at 19:47I have a C#
code embedded in a script task in SSIS
, and I installed NewtonSoft.Json
for some json processing. When I run the package, below error shows up:
Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
Despite trying all solutions and recommendations (uninstall & re-install the package, both from NuGet manager and through console, or adding the reference manually, etc.. ), whenever I run the SSIS package I still get the same error and the script task component fails.
I am using Visual Studio 2017 (SSDT).
How to solve the issue permanently?
ANSWER
Answered 2021-Jan-26 at 17:24With SSIS, you can only reference assemblies installed on the GAC. Use gacutil, from Windows SDK to install the required assembly to the GAC
1gacutil -I "[DriveLetter]:\[PathToBinDirectoryInVSProject]\gac.dll"
2
QUESTION
Is there an automated way to split a JSON(B) column into multiple columns in PostgreSQL?
Asked 2020-Sep-07 at 16:54So I have a PostgreSQL (TimescaleDB) table that looks like this:
1╔════════════════════════════╦═══════╦═══════╗
2║ tags ║ time ║ value ║
3╠════════════════════════════╬═══════╬═══════╣
4║ {"a": "test", "c": "test"} ║ 10:24 ║ 123 ║
5║ {"b": "test", "c": "test"} ║ 10:25 ║ 110 ║
6║ {"b": "test"} ║ 10:26 ║ 130 ║
7╚════════════════════════════╩═══════╩═══════╝
8
And I would like to split the JSON(B) column into multiple columns like this:
1╔════════════════════════════╦═══════╦═══════╗
2║ tags ║ time ║ value ║
3╠════════════════════════════╬═══════╬═══════╣
4║ {"a": "test", "c": "test"} ║ 10:24 ║ 123 ║
5║ {"b": "test", "c": "test"} ║ 10:25 ║ 110 ║
6║ {"b": "test"} ║ 10:26 ║ 130 ║
7╚════════════════════════════╩═══════╩═══════╝
8╔════════╦════════╦════════╦═══════╦═══════╗
9║ a ║ b ║ c ║ time ║ value ║
10╠════════╬════════╬════════╬═══════╬═══════╣
11║ "test" ║ ║ "test" ║ 10:24 ║ 123 ║
12║ ║ "test" ║ "test" ║ 10:25 ║ 110 ║
13║ ║ "test" ║ ║ 10:26 ║ 130 ║
14╚════════╩════════╩════════╩═══════╩═══════╝
15
I looked into the JSON Processing Functions and it seems that those require finding all the JSON(B) attributes and types. Is there a way to do this automatically?
ANSWER
Answered 2020-Sep-07 at 16:54There is no way to make this dynamic. The number (and types) of all columns of a query must be known to the database when parsing the statement, long before it's actually executed.
If you always have the same structure you can create a type:
1╔════════════════════════════╦═══════╦═══════╗
2║ tags ║ time ║ value ║
3╠════════════════════════════╬═══════╬═══════╣
4║ {"a": "test", "c": "test"} ║ 10:24 ║ 123 ║
5║ {"b": "test", "c": "test"} ║ 10:25 ║ 110 ║
6║ {"b": "test"} ║ 10:26 ║ 130 ║
7╚════════════════════════════╩═══════╩═══════╝
8╔════════╦════════╦════════╦═══════╦═══════╗
9║ a ║ b ║ c ║ time ║ value ║
10╠════════╬════════╬════════╬═══════╬═══════╣
11║ "test" ║ ║ "test" ║ 10:24 ║ 123 ║
12║ ║ "test" ║ "test" ║ 10:25 ║ 110 ║
13║ ║ "test" ║ ║ 10:26 ║ 130 ║
14╚════════╩════════╩════════╩═══════╩═══════╝
15create type tag_type as (a text, b text, c text);
16
and then use jsonb_populate_record()
1╔════════════════════════════╦═══════╦═══════╗
2║ tags ║ time ║ value ║
3╠════════════════════════════╬═══════╬═══════╣
4║ {"a": "test", "c": "test"} ║ 10:24 ║ 123 ║
5║ {"b": "test", "c": "test"} ║ 10:25 ║ 110 ║
6║ {"b": "test"} ║ 10:26 ║ 130 ║
7╚════════════════════════════╩═══════╩═══════╝
8╔════════╦════════╦════════╦═══════╦═══════╗
9║ a ║ b ║ c ║ time ║ value ║
10╠════════╬════════╬════════╬═══════╬═══════╣
11║ "test" ║ ║ "test" ║ 10:24 ║ 123 ║
12║ ║ "test" ║ "test" ║ 10:25 ║ 110 ║
13║ ║ "test" ║ ║ 10:26 ║ 130 ║
14╚════════╩════════╩════════╩═══════╩═══════╝
15create type tag_type as (a text, b text, c text);
16select (jsonb_populate_record(null::tag_type, tags)).*, time, value
17from the_table;
18
QUESTION
Register Java Class in Flink Cluster
Asked 2020-Aug-23 at 22:02I am running my Fat Jar in Flink Cluster which reads Kafka and saves in Cassandra, the code is,
1 final Properties prop = getProperties();
2 final FlinkKafkaConsumer<String> flinkConsumer = new FlinkKafkaConsumer<>
3 (kafkaTopicName, new SimpleStringSchema(), prop);
4 flinkConsumer.setStartFromEarliest();
5
6 final DataStream<String> stream = env.addSource(flinkConsumer);
7 DataStream<Person> sensorStreaming = stream.flatMap(new FlatMapFunction<String, Person>() {
8 @Override
9 public void flatMap(String value, Collector<Person> out) throws Exception {
10 try {
11 out.collect(objectMapper.readValue(value, Person.class));
12 } catch (JsonProcessingException e) {
13 logger.error("Json Processing Exception", e);
14 }
15 }
16 });
17 savePersonDetails(sensorStreaming);
18 env.execute();
19
and The Person POJO contains,
1 final Properties prop = getProperties();
2 final FlinkKafkaConsumer<String> flinkConsumer = new FlinkKafkaConsumer<>
3 (kafkaTopicName, new SimpleStringSchema(), prop);
4 flinkConsumer.setStartFromEarliest();
5
6 final DataStream<String> stream = env.addSource(flinkConsumer);
7 DataStream<Person> sensorStreaming = stream.flatMap(new FlatMapFunction<String, Person>() {
8 @Override
9 public void flatMap(String value, Collector<Person> out) throws Exception {
10 try {
11 out.collect(objectMapper.readValue(value, Person.class));
12 } catch (JsonProcessingException e) {
13 logger.error("Json Processing Exception", e);
14 }
15 }
16 });
17 savePersonDetails(sensorStreaming);
18 env.execute();
19 @Column(name = "event_time")
20 private Instant eventTime;
21
There is codec required to store Instant
as below for Cassandra side,
1 final Properties prop = getProperties();
2 final FlinkKafkaConsumer<String> flinkConsumer = new FlinkKafkaConsumer<>
3 (kafkaTopicName, new SimpleStringSchema(), prop);
4 flinkConsumer.setStartFromEarliest();
5
6 final DataStream<String> stream = env.addSource(flinkConsumer);
7 DataStream<Person> sensorStreaming = stream.flatMap(new FlatMapFunction<String, Person>() {
8 @Override
9 public void flatMap(String value, Collector<Person> out) throws Exception {
10 try {
11 out.collect(objectMapper.readValue(value, Person.class));
12 } catch (JsonProcessingException e) {
13 logger.error("Json Processing Exception", e);
14 }
15 }
16 });
17 savePersonDetails(sensorStreaming);
18 env.execute();
19 @Column(name = "event_time")
20 private Instant eventTime;
21final Cluster cluster = ClusterManager.getCluster(cassandraIpAddress);
22cluster.getConfiguration().getCodecRegistry().register(InstantCodec.instance);
23
When i run standalone works fine, but when i run local cluster throws me an error as below,
1 final Properties prop = getProperties();
2 final FlinkKafkaConsumer<String> flinkConsumer = new FlinkKafkaConsumer<>
3 (kafkaTopicName, new SimpleStringSchema(), prop);
4 flinkConsumer.setStartFromEarliest();
5
6 final DataStream<String> stream = env.addSource(flinkConsumer);
7 DataStream<Person> sensorStreaming = stream.flatMap(new FlatMapFunction<String, Person>() {
8 @Override
9 public void flatMap(String value, Collector<Person> out) throws Exception {
10 try {
11 out.collect(objectMapper.readValue(value, Person.class));
12 } catch (JsonProcessingException e) {
13 logger.error("Json Processing Exception", e);
14 }
15 }
16 });
17 savePersonDetails(sensorStreaming);
18 env.execute();
19 @Column(name = "event_time")
20 private Instant eventTime;
21final Cluster cluster = ClusterManager.getCluster(cassandraIpAddress);
22cluster.getConfiguration().getCodecRegistry().register(InstantCodec.instance);
23Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [timestamp <-> java.time.Instant]
24 at com.datastax.driver.core.CodecRegistry.notFound(CodecRegistry.java:679)
25 at com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:526)
26 at com.datastax.driver.core.CodecRegistry.findCodec(CodecRegistry.java:506)
27 at com.datastax.driver.core.CodecRegistry.access$200(CodecRegistry.java:140)
28 at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:211)
29 at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:208)
30
I read the below document for registering,
https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/custom_serializers.html
but InstantCodec
is 3rd party one. How can i register it?
ANSWER
Answered 2020-Aug-23 at 22:02I solved the problem, there was LocalDateTime
which was emitting from and when i was converting with same type, there was above error. I changed the type into java.util Date
type then it worked.
QUESTION
A simple way to parse XML with repeated element using Jackson
Asked 2020-Aug-23 at 14:42I am looking for a simple way to parse an XML structure with a repeated element using Jackson. Here is a simplified example:
1<root>
2 <a>
3 <x>
4 <b>some content</b>
5 <c>some content</c>
6 </x>
7 <x>
8 <b>some content</b>
9 <c>some content</c>
10 </x>
11 ...
12 <x>
13 <b>some content</b>
14 <c>some content</c>
15 </x>
16 </a>
17
18 ... some other content ...
19</root>
20
I would like to collect all the x
elements in a list or array The problem is that when using something like:
1<root>
2 <a>
3 <x>
4 <b>some content</b>
5 <c>some content</c>
6 </x>
7 <x>
8 <b>some content</b>
9 <c>some content</c>
10 </x>
11 ...
12 <x>
13 <b>some content</b>
14 <c>some content</c>
15 </x>
16 </a>
17
18 ... some other content ...
19</root>
20XmlMapper().readTree(xml).get("a").fields()
21
the result contains only the last instance of x
so it looks like some map key gets overwritten. There is a solution using JsonParser
e.g.: XmlMapper().createParser(xml)
but it's a bit icky.
Is there a better way?
Edit
The way I read the "Known Limitations" section in the README , XML seems to be a second class citizen in Jackson. I accept @galuszkak 's answer as it is what it is , but to my mind when a developer invokes XmlMapper().readTree(xml)
they do not expect XML processing to be shoehorned into JSON processing model with the limitations that come with that approach.
ANSWER
Answered 2020-Aug-23 at 14:42The problem mentioned here is described in this Github issue: https://github.com/FasterXML/jackson-dataformat-xml/issues/187
Basically what is happening is that Jackson is translating XML tree structure in JsonNode data model and this will not work as it's not supported.
There is 2 options described in that Github issue:
- Fully transform this XML to JSON (answer from @cawena on Github)
- Or if you know your data structure to just use answer from p0sitron which is:
Code:
1<root>
2 <a>
3 <x>
4 <b>some content</b>
5 <c>some content</c>
6 </x>
7 <x>
8 <b>some content</b>
9 <c>some content</c>
10 </x>
11 ...
12 <x>
13 <b>some content</b>
14 <c>some content</c>
15 </x>
16 </a>
17
18 ... some other content ...
19</root>
20XmlMapper().readTree(xml).get("a").fields()
21List<List<JsonNode>> elA = xmlMapper.readValue(xml, new TypeReference<List<List<JsonNode>>>() { });
22assertEquals(3, elA.get(0).size());
23
QUESTION
Shiny.io cannot deploy the application
Asked 2020-Jul-28 at 21:34I was trying to create an interactive map with the Shiny web application, however, after I published it to my shiny.io account, clicking the URL will only yield: shiny.io application page
1An error has occurred!
2
3An error has occurred. Check your logs or contact the app author for clarification.
4
Can you help me with it? Thanks!
Here are the logs of the application:
1An error has occurred!
2
3An error has occurred. Check your logs or contact the app author for clarification.
42020-07-28T20:32:42.887039+00:00 shinyapps[2621249]: jsonlite version: 1.6.1
52020-07-28T20:32:42.887039+00:00 shinyapps[2621249]: RJSONIO version: (none)
62020-07-28T20:32:42.887050+00:00 shinyapps[2621249]: htmltools version: 0.5.0
72020-07-28T20:32:42.887235+00:00 shinyapps[2621249]: Using pandoc: /opt/connect/ext/pandoc2
82020-07-28T20:32:43.039412+00:00 shinyapps[2621249]:
92020-07-28T20:32:43.039413+00:00 shinyapps[2621249]: Starting R with process ID: '58'
102020-07-28T20:32:43.106062+00:00 shinyapps[2621249]: Listening on http://127.0.0.1:36754
112020-07-28T20:32:43.106061+00:00 shinyapps[2621249]:
122020-07-28T20:32:43.035592+00:00 shinyapps[2621249]: Using jsonlite for JSON processing
132020-07-28T20:32:43.299242+00:00 shinyapps[2621249]: Warning: Error in plotlyOutput: could not find function "plotlyOutput"
142020-07-28T20:32:43.304719+00:00 shinyapps[2621249]: 99: div
152020-07-28T20:32:43.304717+00:00 shinyapps[2621249]: 100: dots_list
162020-07-28T20:32:43.304719+00:00 shinyapps[2621249]: 98: tabPanel
172020-07-28T20:53:57.079846+00:00 shinyapps[2621249]: Running on host: 220810008dc5
182020-07-28T20:53:57.085768+00:00 shinyapps[2621249]: Server version: 1.8.4-11
192020-07-28T20:53:57.085785+00:00 shinyapps[2621249]: LANG: en_US.UTF-8
202020-07-28T20:53:57.085827+00:00 shinyapps[2621249]: R version: 4.0.0
212020-07-28T20:53:57.085867+00:00 shinyapps[2621249]: shiny version: 1.5.0
222020-07-28T20:53:57.085869+00:00 shinyapps[2621249]: httpuv version: 1.5.4
232020-07-28T20:53:57.085881+00:00 shinyapps[2621249]: rmarkdown version: (none)
242020-07-28T20:53:57.085882+00:00 shinyapps[2621249]: knitr version: (none)
252020-07-28T20:53:57.085895+00:00 shinyapps[2621249]: jsonlite version: 1.6.1
262020-07-28T20:53:57.085909+00:00 shinyapps[2621249]: RJSONIO version: (none)
272020-07-28T20:53:57.085959+00:00 shinyapps[2621249]: htmltools version: 0.5.0
282020-07-28T20:53:57.086171+00:00 shinyapps[2621249]: Using pandoc: /opt/connect/ext/pandoc2
292020-07-28T20:53:57.244930+00:00 shinyapps[2621249]: Using jsonlite for JSON processing
302020-07-28T20:53:57.248899+00:00 shinyapps[2621249]:
312020-07-28T20:53:57.248900+00:00 shinyapps[2621249]: Starting R with process ID: '24'
322020-07-28T20:53:57.319981+00:00 shinyapps[2621249]:
332020-07-28T20:53:57.319982+00:00 shinyapps[2621249]: Listening on http://127.0.0.1:44567
342020-07-28T20:56:14.943220+00:00 shinyapps[2621249]: Running on host: 220810008dc5
352020-07-28T20:56:14.950036+00:00 shinyapps[2621249]: Server version: 1.8.4-11
362020-07-28T20:56:14.950099+00:00 shinyapps[2621249]: httpuv version: 1.5.4
372020-07-28T20:56:14.950046+00:00 shinyapps[2621249]: LANG: en_US.UTF-8
382020-07-28T20:56:14.950063+00:00 shinyapps[2621249]: R version: 4.0.0
392020-07-28T20:56:14.950165+00:00 shinyapps[2621249]: knitr version: (none)
402020-07-28T20:56:14.950089+00:00 shinyapps[2621249]: shiny version: 1.5.0
412020-07-28T20:56:14.950105+00:00 shinyapps[2621249]: rmarkdown version: (none)
422020-07-28T20:56:14.950182+00:00 shinyapps[2621249]: jsonlite version: 1.6.1
432020-07-28T20:56:14.950410+00:00 shinyapps[2621249]: Using pandoc: /opt/connect/ext/pandoc2
442020-07-28T20:56:15.113622+00:00 shinyapps[2621249]: Using jsonlite for JSON processing
452020-07-28T20:56:14.950182+00:00 shinyapps[2621249]: RJSONIO version: (none)
462020-07-28T20:56:14.950183+00:00 shinyapps[2621249]: htmltools version: 0.5.0
472020-07-28T20:56:15.118668+00:00 shinyapps[2621249]: Starting R with process ID: '73'
482020-07-28T20:56:15.118666+00:00 shinyapps[2621249]:
492020-07-28T20:56:15.192554+00:00 shinyapps[2621249]:
502020-07-28T20:56:15.192556+00:00 shinyapps[2621249]: Listening on http://127.0.0.1:37222
512020-07-28T20:56:15.320813+00:00 shinyapps[2621249]: Warning: Error in plotlyOutput: could not find function "plotlyOutput"
522020-07-28T20:56:15.326689+00:00 shinyapps[2621249]: 100: dots_list
532020-07-28T20:56:15.326691+00:00 shinyapps[2621249]: 99: div
542020-07-28T20:56:15.326692+00:00 shinyapps[2621249]: 98: tabPanel
55
It worked perfectly in RStudio with the following ui.R and Server.R:
1An error has occurred!
2
3An error has occurred. Check your logs or contact the app author for clarification.
42020-07-28T20:32:42.887039+00:00 shinyapps[2621249]: jsonlite version: 1.6.1
52020-07-28T20:32:42.887039+00:00 shinyapps[2621249]: RJSONIO version: (none)
62020-07-28T20:32:42.887050+00:00 shinyapps[2621249]: htmltools version: 0.5.0
72020-07-28T20:32:42.887235+00:00 shinyapps[2621249]: Using pandoc: /opt/connect/ext/pandoc2
82020-07-28T20:32:43.039412+00:00 shinyapps[2621249]:
92020-07-28T20:32:43.039413+00:00 shinyapps[2621249]: Starting R with process ID: '58'
102020-07-28T20:32:43.106062+00:00 shinyapps[2621249]: Listening on http://127.0.0.1:36754
112020-07-28T20:32:43.106061+00:00 shinyapps[2621249]:
122020-07-28T20:32:43.035592+00:00 shinyapps[2621249]: Using jsonlite for JSON processing
132020-07-28T20:32:43.299242+00:00 shinyapps[2621249]: Warning: Error in plotlyOutput: could not find function "plotlyOutput"
142020-07-28T20:32:43.304719+00:00 shinyapps[2621249]: 99: div
152020-07-28T20:32:43.304717+00:00 shinyapps[2621249]: 100: dots_list
162020-07-28T20:32:43.304719+00:00 shinyapps[2621249]: 98: tabPanel
172020-07-28T20:53:57.079846+00:00 shinyapps[2621249]: Running on host: 220810008dc5
182020-07-28T20:53:57.085768+00:00 shinyapps[2621249]: Server version: 1.8.4-11
192020-07-28T20:53:57.085785+00:00 shinyapps[2621249]: LANG: en_US.UTF-8
202020-07-28T20:53:57.085827+00:00 shinyapps[2621249]: R version: 4.0.0
212020-07-28T20:53:57.085867+00:00 shinyapps[2621249]: shiny version: 1.5.0
222020-07-28T20:53:57.085869+00:00 shinyapps[2621249]: httpuv version: 1.5.4
232020-07-28T20:53:57.085881+00:00 shinyapps[2621249]: rmarkdown version: (none)
242020-07-28T20:53:57.085882+00:00 shinyapps[2621249]: knitr version: (none)
252020-07-28T20:53:57.085895+00:00 shinyapps[2621249]: jsonlite version: 1.6.1
262020-07-28T20:53:57.085909+00:00 shinyapps[2621249]: RJSONIO version: (none)
272020-07-28T20:53:57.085959+00:00 shinyapps[2621249]: htmltools version: 0.5.0
282020-07-28T20:53:57.086171+00:00 shinyapps[2621249]: Using pandoc: /opt/connect/ext/pandoc2
292020-07-28T20:53:57.244930+00:00 shinyapps[2621249]: Using jsonlite for JSON processing
302020-07-28T20:53:57.248899+00:00 shinyapps[2621249]:
312020-07-28T20:53:57.248900+00:00 shinyapps[2621249]: Starting R with process ID: '24'
322020-07-28T20:53:57.319981+00:00 shinyapps[2621249]:
332020-07-28T20:53:57.319982+00:00 shinyapps[2621249]: Listening on http://127.0.0.1:44567
342020-07-28T20:56:14.943220+00:00 shinyapps[2621249]: Running on host: 220810008dc5
352020-07-28T20:56:14.950036+00:00 shinyapps[2621249]: Server version: 1.8.4-11
362020-07-28T20:56:14.950099+00:00 shinyapps[2621249]: httpuv version: 1.5.4
372020-07-28T20:56:14.950046+00:00 shinyapps[2621249]: LANG: en_US.UTF-8
382020-07-28T20:56:14.950063+00:00 shinyapps[2621249]: R version: 4.0.0
392020-07-28T20:56:14.950165+00:00 shinyapps[2621249]: knitr version: (none)
402020-07-28T20:56:14.950089+00:00 shinyapps[2621249]: shiny version: 1.5.0
412020-07-28T20:56:14.950105+00:00 shinyapps[2621249]: rmarkdown version: (none)
422020-07-28T20:56:14.950182+00:00 shinyapps[2621249]: jsonlite version: 1.6.1
432020-07-28T20:56:14.950410+00:00 shinyapps[2621249]: Using pandoc: /opt/connect/ext/pandoc2
442020-07-28T20:56:15.113622+00:00 shinyapps[2621249]: Using jsonlite for JSON processing
452020-07-28T20:56:14.950182+00:00 shinyapps[2621249]: RJSONIO version: (none)
462020-07-28T20:56:14.950183+00:00 shinyapps[2621249]: htmltools version: 0.5.0
472020-07-28T20:56:15.118668+00:00 shinyapps[2621249]: Starting R with process ID: '73'
482020-07-28T20:56:15.118666+00:00 shinyapps[2621249]:
492020-07-28T20:56:15.192554+00:00 shinyapps[2621249]:
502020-07-28T20:56:15.192556+00:00 shinyapps[2621249]: Listening on http://127.0.0.1:37222
512020-07-28T20:56:15.320813+00:00 shinyapps[2621249]: Warning: Error in plotlyOutput: could not find function "plotlyOutput"
522020-07-28T20:56:15.326689+00:00 shinyapps[2621249]: 100: dots_list
532020-07-28T20:56:15.326691+00:00 shinyapps[2621249]: 99: div
542020-07-28T20:56:15.326692+00:00 shinyapps[2621249]: 98: tabPanel
55library(shiny)
56library(leaflet)
57
58shinyUI(fluidPage(
59
60 titlePanel("JHU COVID-19 Modeling Visualization Map"),
61
62 sidebarLayout(
63 sidebarPanel(
64 checkboxGroupInput("statesInput", "Choose the State(s)",
65 c("AL", "MO", "AK", "MT", "AZ", "NE",
66 "AR", "NV", "CA", "NH", "CO", "NJ",
67 "CT", "NM", "DE", "NY", "DC", "NC",
68 "FL", "ND", "GA", "OH", "HI", "OK",
69 "ID", "OR", "IL", "PA", "IN", "RI",
70 "IA", "SC", "KS", "SD", "KY", "TN",
71 "LA", "TX", "ME", "UT", "MD", "VT",
72 "MA", "VA", "MI", "WA", "MN", "WV",
73 "MS", "WI", "WY"),
74 inline = TRUE),
75
76 submitButton("Submit"),
77 ),
78
79 mainPanel(
80 tabsetPanel(type = "tabs",
81 tabPanel("County Level", plotlyOutput("countyPolygonMap")),
82 tabPanel("State Level", leafletOutput("statePolygonMap"))
83 )
84 )
85)))
86
87
1An error has occurred!
2
3An error has occurred. Check your logs or contact the app author for clarification.
42020-07-28T20:32:42.887039+00:00 shinyapps[2621249]: jsonlite version: 1.6.1
52020-07-28T20:32:42.887039+00:00 shinyapps[2621249]: RJSONIO version: (none)
62020-07-28T20:32:42.887050+00:00 shinyapps[2621249]: htmltools version: 0.5.0
72020-07-28T20:32:42.887235+00:00 shinyapps[2621249]: Using pandoc: /opt/connect/ext/pandoc2
82020-07-28T20:32:43.039412+00:00 shinyapps[2621249]:
92020-07-28T20:32:43.039413+00:00 shinyapps[2621249]: Starting R with process ID: '58'
102020-07-28T20:32:43.106062+00:00 shinyapps[2621249]: Listening on http://127.0.0.1:36754
112020-07-28T20:32:43.106061+00:00 shinyapps[2621249]:
122020-07-28T20:32:43.035592+00:00 shinyapps[2621249]: Using jsonlite for JSON processing
132020-07-28T20:32:43.299242+00:00 shinyapps[2621249]: Warning: Error in plotlyOutput: could not find function "plotlyOutput"
142020-07-28T20:32:43.304719+00:00 shinyapps[2621249]: 99: div
152020-07-28T20:32:43.304717+00:00 shinyapps[2621249]: 100: dots_list
162020-07-28T20:32:43.304719+00:00 shinyapps[2621249]: 98: tabPanel
172020-07-28T20:53:57.079846+00:00 shinyapps[2621249]: Running on host: 220810008dc5
182020-07-28T20:53:57.085768+00:00 shinyapps[2621249]: Server version: 1.8.4-11
192020-07-28T20:53:57.085785+00:00 shinyapps[2621249]: LANG: en_US.UTF-8
202020-07-28T20:53:57.085827+00:00 shinyapps[2621249]: R version: 4.0.0
212020-07-28T20:53:57.085867+00:00 shinyapps[2621249]: shiny version: 1.5.0
222020-07-28T20:53:57.085869+00:00 shinyapps[2621249]: httpuv version: 1.5.4
232020-07-28T20:53:57.085881+00:00 shinyapps[2621249]: rmarkdown version: (none)
242020-07-28T20:53:57.085882+00:00 shinyapps[2621249]: knitr version: (none)
252020-07-28T20:53:57.085895+00:00 shinyapps[2621249]: jsonlite version: 1.6.1
262020-07-28T20:53:57.085909+00:00 shinyapps[2621249]: RJSONIO version: (none)
272020-07-28T20:53:57.085959+00:00 shinyapps[2621249]: htmltools version: 0.5.0
282020-07-28T20:53:57.086171+00:00 shinyapps[2621249]: Using pandoc: /opt/connect/ext/pandoc2
292020-07-28T20:53:57.244930+00:00 shinyapps[2621249]: Using jsonlite for JSON processing
302020-07-28T20:53:57.248899+00:00 shinyapps[2621249]:
312020-07-28T20:53:57.248900+00:00 shinyapps[2621249]: Starting R with process ID: '24'
322020-07-28T20:53:57.319981+00:00 shinyapps[2621249]:
332020-07-28T20:53:57.319982+00:00 shinyapps[2621249]: Listening on http://127.0.0.1:44567
342020-07-28T20:56:14.943220+00:00 shinyapps[2621249]: Running on host: 220810008dc5
352020-07-28T20:56:14.950036+00:00 shinyapps[2621249]: Server version: 1.8.4-11
362020-07-28T20:56:14.950099+00:00 shinyapps[2621249]: httpuv version: 1.5.4
372020-07-28T20:56:14.950046+00:00 shinyapps[2621249]: LANG: en_US.UTF-8
382020-07-28T20:56:14.950063+00:00 shinyapps[2621249]: R version: 4.0.0
392020-07-28T20:56:14.950165+00:00 shinyapps[2621249]: knitr version: (none)
402020-07-28T20:56:14.950089+00:00 shinyapps[2621249]: shiny version: 1.5.0
412020-07-28T20:56:14.950105+00:00 shinyapps[2621249]: rmarkdown version: (none)
422020-07-28T20:56:14.950182+00:00 shinyapps[2621249]: jsonlite version: 1.6.1
432020-07-28T20:56:14.950410+00:00 shinyapps[2621249]: Using pandoc: /opt/connect/ext/pandoc2
442020-07-28T20:56:15.113622+00:00 shinyapps[2621249]: Using jsonlite for JSON processing
452020-07-28T20:56:14.950182+00:00 shinyapps[2621249]: RJSONIO version: (none)
462020-07-28T20:56:14.950183+00:00 shinyapps[2621249]: htmltools version: 0.5.0
472020-07-28T20:56:15.118668+00:00 shinyapps[2621249]: Starting R with process ID: '73'
482020-07-28T20:56:15.118666+00:00 shinyapps[2621249]:
492020-07-28T20:56:15.192554+00:00 shinyapps[2621249]:
502020-07-28T20:56:15.192556+00:00 shinyapps[2621249]: Listening on http://127.0.0.1:37222
512020-07-28T20:56:15.320813+00:00 shinyapps[2621249]: Warning: Error in plotlyOutput: could not find function "plotlyOutput"
522020-07-28T20:56:15.326689+00:00 shinyapps[2621249]: 100: dots_list
532020-07-28T20:56:15.326691+00:00 shinyapps[2621249]: 99: div
542020-07-28T20:56:15.326692+00:00 shinyapps[2621249]: 98: tabPanel
55library(shiny)
56library(leaflet)
57
58shinyUI(fluidPage(
59
60 titlePanel("JHU COVID-19 Modeling Visualization Map"),
61
62 sidebarLayout(
63 sidebarPanel(
64 checkboxGroupInput("statesInput", "Choose the State(s)",
65 c("AL", "MO", "AK", "MT", "AZ", "NE",
66 "AR", "NV", "CA", "NH", "CO", "NJ",
67 "CT", "NM", "DE", "NY", "DC", "NC",
68 "FL", "ND", "GA", "OH", "HI", "OK",
69 "ID", "OR", "IL", "PA", "IN", "RI",
70 "IA", "SC", "KS", "SD", "KY", "TN",
71 "LA", "TX", "ME", "UT", "MD", "VT",
72 "MA", "VA", "MI", "WA", "MN", "WV",
73 "MS", "WI", "WY"),
74 inline = TRUE),
75
76 submitButton("Submit"),
77 ),
78
79 mainPanel(
80 tabsetPanel(type = "tabs",
81 tabPanel("County Level", plotlyOutput("countyPolygonMap")),
82 tabPanel("State Level", leafletOutput("statePolygonMap"))
83 )
84 )
85)))
86
87library(shiny)
88library(leaflet)
89library(magrittr)
90library(rgdal)
91
92shinyServer(function(input, output) {
93 library(rjson)
94 library(plotly)
95 library(dplyr)
96
97 statepolygonZip <- download.file("https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_state_500k.zip",
98 destfile = "cb_2018_us_state_500k.zip");
99 unzip("cb_2018_us_state_500k.zip");
100 statePolygonData <- readOGR("cb_2018_us_state_500k.shp", layer = "cb_2018_us_state_500k",
101 GDAL1_integer64_policy = TRUE);
102 ## obtaning the state shape file data provided by cencus.gov
103 ## for more categories of region shape file:
104 ## https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.html
105
106
107 output$countyPolygonMap <- renderPlotly({
108 url <- 'https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json'
109 countyGeo <- rjson::fromJSON(file=url)
110 ## Obtaining the geographical file for all U.S. counties
111 url2<- "https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv"
112 df <- read.csv(url2, colClasses=c(fips="character"))
113 names(df)[2] = "unemployment"
114 ## obtaining the unemployment rate data
115 url3 <- "https://storage.googleapis.com/kagglesdsdata/datasets%2F579969%2F1374720%2Fus_county.csv?GoogleAccessId=gcp-kaggle-com@kaggle-161607.iam.gserviceaccount.com&Expires=1596139521&Signature=easqHBFZ757D%2F7LVyDM%2BF%2FIMU6l2OEY6giqVvIC0l0tSSe%2Fohq6NC%2FLFKbsIV6FdFALmPUqG9vATbg0cuRVVwGQMsoUOjlW%2BZLhTVluxbYh1dDE1MTFzWRpzlSH18ejIwqa61F0ARJ%2Bpq6ryIfJuE7wQQ1rOCEpaVB9m%2FP7QaZm2gBJeHYLXJXcvO8w1p0sEnqRsGAesg2Fgj%2Bv8unPGNtDJekEWuNbl1K9k7CAaZWjG2QQ94LB9tAPvfKqykDWDD7w6yN3YFkcfu7kUmjs0CybnMD6IP%2FM5hvJXuUTIie0MOMTWt5bIua4qcTHxIxR5l918y1H17JA2HHrnKLVY%2BA%3D%3D"
116 county <- read.csv(url3)
117 county$nfips <- sprintf("%05d",county$fips)
118
119 countyPolygonMap <- plot_ly() %>% add_trace(
120 type="choroplethmapbox",
121 geojson=countyGeo,
122 locations=county$nfips,
123 z=~county$population,
124 colorscale="Viridis",
125 zmin=200,
126 zmax=1100000,
127 marker=list(line=list(width=0),opacity=0.5)
128 ) %>% layout(
129 mapbox=list(
130 style="carto-positron",
131 zoom =2,
132 center=list(lon= -95.71, lat=37.09))
133 );
134 countyPolygonMap;
135 ## generating the interactive plotly map
136 })
137
138 output$statePolygonMap <-renderLeaflet ({
139 statesAbbr <- subset(statePolygonData, input$statesInput %in% statePolygonData$STUSPS);
140 ## subsetting the shape file with the selected states
141
142 leaflet(statesAbbr) %>%
143 addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
144 opacity = 1.0, fillOpacity = 0.5,
145 fillColor = ~colorQuantile("YlOrRd", ALAND)(ALAND),
146 highlightOptions = highlightOptions
147 (color = "white", weight = 2,bringToFront = TRUE))
148 })
149 ## producing the map with polygon boundary on the state level
150})
151
ANSWER
Answered 2020-Jul-28 at 21:15I am thinking you mean shinyapps.io. To get to the logs:
- Click on the dashboard view (the left-side panel).
- Click on the name of your app (a hyperlink)
- Click on the logs button at the top of the screen
QUESTION
How to deploy shiny app to shinyapps.io from drake plan
Asked 2020-Jul-16 at 18:20This is a follow-on question from closing the loop on passing the app and data to a Shiny deployment function:
How to use shiny app as a target in drake
I would like to deploy a Shiny app directly from a drake plan as below.
1library(drake)
2library(shiny)
3
4plan <- drake_plan(
5 cars_data = mtcars,
6 deployment = custom_deployment_function(file_in("app.R"), cars_data)
7)
8
9custom_shiny_deployment <- function(file, data_input) {
10
11 rsconnect::deployApp(
12 appFiles = file,
13 appName = "cars",
14 forceUpdate = TRUE
15 )
16}
17
18Saved as "app.R" in project working directory (the app works outside of drake if data_input <- mtcars) :
19
20shinyApp(
21 ui = fluidPage(
22 selectInput("variable", "Variable:",
23 c("Cylinders" = "cyl",
24 "Transmission" = "am")),
25 tableOutput("data")
26 ),
27 server = function(input, output) {
28 output$data <- renderTable({
29 data_input[, c("mpg", input$variable), drop = FALSE]
30 }, rownames = TRUE)
31 }
32)
33
34
Logs from shinyapps.io shows "cars_data" from drake is not being passed to the Shiny server "data_input" in the custom_deployment_function environment:
1library(drake)
2library(shiny)
3
4plan <- drake_plan(
5 cars_data = mtcars,
6 deployment = custom_deployment_function(file_in("app.R"), cars_data)
7)
8
9custom_shiny_deployment <- function(file, data_input) {
10
11 rsconnect::deployApp(
12 appFiles = file,
13 appName = "cars",
14 forceUpdate = TRUE
15 )
16}
17
18Saved as "app.R" in project working directory (the app works outside of drake if data_input <- mtcars) :
19
20shinyApp(
21 ui = fluidPage(
22 selectInput("variable", "Variable:",
23 c("Cylinders" = "cyl",
24 "Transmission" = "am")),
25 tableOutput("data")
26 ),
27 server = function(input, output) {
28 output$data <- renderTable({
29 data_input[, c("mpg", input$variable), drop = FALSE]
30 }, rownames = TRUE)
31 }
32)
33
342020-07-14T20:12:57.418989+00:00 shinyapps[2569696]: htmltools version: 0.5.0
352020-07-14T20:12:57.419186+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
362020-07-14T20:12:57.589960+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
372020-07-14T20:12:57.593223+00:00 shinyapps[2569696]:
382020-07-14T20:12:57.593224+00:00 shinyapps[2569696]: Starting R with process ID: '25'
392020-07-14T20:12:57.628389+00:00 shinyapps[2569696]:
402020-07-14T20:12:57.628390+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:38608
412020-07-14T20:13:14.686424+00:00 shinyapps[2569696]: Running on host: e89f96d02b6e
422020-07-14T20:13:14.691423+00:00 shinyapps[2569696]: Server version: 1.8.4-11
432020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
442020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: R version: 4.0.0
452020-07-14T20:13:14.691437+00:00 shinyapps[2569696]: shiny version: 1.5.0
462020-07-14T20:13:14.691467+00:00 shinyapps[2569696]: rmarkdown version: (none)
472020-07-14T20:13:14.691648+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
482020-07-14T20:13:14.691475+00:00 shinyapps[2569696]: knitr version: (none)
492020-07-14T20:13:14.857243+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
502020-07-14T20:13:14.691443+00:00 shinyapps[2569696]: httpuv version: 1.5.4
512020-07-14T20:13:14.895595+00:00 shinyapps[2569696]:
522020-07-14T20:13:14.691480+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
532020-07-14T20:13:14.860404+00:00 shinyapps[2569696]:
542020-07-14T20:13:14.860404+00:00 shinyapps[2569696]: Starting R with process ID: '41'
552020-07-14T20:13:14.895596+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:42022
562020-07-14T20:13:14.691496+00:00 shinyapps[2569696]: RJSONIO version: (none)
572020-07-14T20:13:14.691506+00:00 shinyapps[2569696]: htmltools version: 0.5.0
582020-07-14T20:15:57.441648+00:00 shinyapps[2569696]: Running on host: a2e664ad9837
592020-07-14T20:15:57.447236+00:00 shinyapps[2569696]: Server version: 1.8.4-11
602020-07-14T20:15:57.447326+00:00 shinyapps[2569696]: R version: 4.0.0
612020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: knitr version: (none)
622020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: rmarkdown version: (none)
632020-07-14T20:15:57.447327+00:00 shinyapps[2569696]: shiny version: 1.5.0
642020-07-14T20:15:57.447260+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
652020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: httpuv version: 1.5.4
662020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
672020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: RJSONIO version: (none)
682020-07-14T20:15:57.667089+00:00 shinyapps[2569696]:
692020-07-14T20:15:57.447494+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
702020-07-14T20:15:57.630039+00:00 shinyapps[2569696]: Starting R with process ID: '24'
712020-07-14T20:15:57.626886+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
722020-07-14T20:15:57.447347+00:00 shinyapps[2569696]: htmltools version: 0.5.0
732020-07-14T20:15:57.630037+00:00 shinyapps[2569696]:
742020-07-14T20:15:57.667090+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:40107
752020-07-14T20:16:14.758082+00:00 shinyapps[2569696]: Warning: Error in renderTable: object 'data_input' not found
762020-07-14T20:16:14.772348+00:00 shinyapps[2569696]: 108: renderTable [/srv/connect/apps/cars/app.R#13]
772020-07-14T20:16:14.772349+00:00 shinyapps[2569696]: 107: func
782020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 94: origRenderFunc
792020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 93: output$data
802020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 13: runApp
812020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 12: fn
822020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 7: connect$retry
832020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 6: eval
842020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 5: eval
85
Apologies if this is trivial, but between drake and shiny, it is escaping me.
ANSWER
Answered 2020-Jul-16 at 18:20Now that I see how you are deploying the app, I can say that this is expected behavior. Yes, your custom_shiny_deployment()
has access to the data, but the deployed app does not because rsconnect::deployApp()
does not ship objects from the calling environment. If you want the data to be available to the app, I recommend saving it (and tracking it with file_in()
and file_out()
) then passing it to the appFiles
argument of deployApp()
via custom_shiny_deployment()
.
Your app.R
can stay like it is.
app.R
is the same as what you wrote.
1library(drake)
2library(shiny)
3
4plan <- drake_plan(
5 cars_data = mtcars,
6 deployment = custom_deployment_function(file_in("app.R"), cars_data)
7)
8
9custom_shiny_deployment <- function(file, data_input) {
10
11 rsconnect::deployApp(
12 appFiles = file,
13 appName = "cars",
14 forceUpdate = TRUE
15 )
16}
17
18Saved as "app.R" in project working directory (the app works outside of drake if data_input <- mtcars) :
19
20shinyApp(
21 ui = fluidPage(
22 selectInput("variable", "Variable:",
23 c("Cylinders" = "cyl",
24 "Transmission" = "am")),
25 tableOutput("data")
26 ),
27 server = function(input, output) {
28 output$data <- renderTable({
29 data_input[, c("mpg", input$variable), drop = FALSE]
30 }, rownames = TRUE)
31 }
32)
33
342020-07-14T20:12:57.418989+00:00 shinyapps[2569696]: htmltools version: 0.5.0
352020-07-14T20:12:57.419186+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
362020-07-14T20:12:57.589960+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
372020-07-14T20:12:57.593223+00:00 shinyapps[2569696]:
382020-07-14T20:12:57.593224+00:00 shinyapps[2569696]: Starting R with process ID: '25'
392020-07-14T20:12:57.628389+00:00 shinyapps[2569696]:
402020-07-14T20:12:57.628390+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:38608
412020-07-14T20:13:14.686424+00:00 shinyapps[2569696]: Running on host: e89f96d02b6e
422020-07-14T20:13:14.691423+00:00 shinyapps[2569696]: Server version: 1.8.4-11
432020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
442020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: R version: 4.0.0
452020-07-14T20:13:14.691437+00:00 shinyapps[2569696]: shiny version: 1.5.0
462020-07-14T20:13:14.691467+00:00 shinyapps[2569696]: rmarkdown version: (none)
472020-07-14T20:13:14.691648+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
482020-07-14T20:13:14.691475+00:00 shinyapps[2569696]: knitr version: (none)
492020-07-14T20:13:14.857243+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
502020-07-14T20:13:14.691443+00:00 shinyapps[2569696]: httpuv version: 1.5.4
512020-07-14T20:13:14.895595+00:00 shinyapps[2569696]:
522020-07-14T20:13:14.691480+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
532020-07-14T20:13:14.860404+00:00 shinyapps[2569696]:
542020-07-14T20:13:14.860404+00:00 shinyapps[2569696]: Starting R with process ID: '41'
552020-07-14T20:13:14.895596+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:42022
562020-07-14T20:13:14.691496+00:00 shinyapps[2569696]: RJSONIO version: (none)
572020-07-14T20:13:14.691506+00:00 shinyapps[2569696]: htmltools version: 0.5.0
582020-07-14T20:15:57.441648+00:00 shinyapps[2569696]: Running on host: a2e664ad9837
592020-07-14T20:15:57.447236+00:00 shinyapps[2569696]: Server version: 1.8.4-11
602020-07-14T20:15:57.447326+00:00 shinyapps[2569696]: R version: 4.0.0
612020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: knitr version: (none)
622020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: rmarkdown version: (none)
632020-07-14T20:15:57.447327+00:00 shinyapps[2569696]: shiny version: 1.5.0
642020-07-14T20:15:57.447260+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
652020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: httpuv version: 1.5.4
662020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
672020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: RJSONIO version: (none)
682020-07-14T20:15:57.667089+00:00 shinyapps[2569696]:
692020-07-14T20:15:57.447494+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
702020-07-14T20:15:57.630039+00:00 shinyapps[2569696]: Starting R with process ID: '24'
712020-07-14T20:15:57.626886+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
722020-07-14T20:15:57.447347+00:00 shinyapps[2569696]: htmltools version: 0.5.0
732020-07-14T20:15:57.630037+00:00 shinyapps[2569696]:
742020-07-14T20:15:57.667090+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:40107
752020-07-14T20:16:14.758082+00:00 shinyapps[2569696]: Warning: Error in renderTable: object 'data_input' not found
762020-07-14T20:16:14.772348+00:00 shinyapps[2569696]: 108: renderTable [/srv/connect/apps/cars/app.R#13]
772020-07-14T20:16:14.772349+00:00 shinyapps[2569696]: 107: func
782020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 94: origRenderFunc
792020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 93: output$data
802020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 13: runApp
812020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 12: fn
822020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 7: connect$retry
832020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 6: eval
842020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 5: eval
85library(shiny)
86
87cars_data <- readRDS("cars_data.RDS")
88
89shinyApp(
90 ui = fluidPage(
91 selectInput("variable", "Variable:",
92 c("Cylinders" = "cyl",
93 "Transmission" = "am")),
94 tableOutput("data")
95 ),
96 server = function(input, output) {
97 output$data <- renderTable({
98 cars_data[, c("mpg", input$variable), drop = FALSE]
99 }, rownames = TRUE)
100 }
101)
102
But from drake
's side, you need something like file_in()
and file_out()
to ensure the correct targets run in the correct order and in response to changes to cars_data.RDS
and app.R
.
1library(drake)
2library(shiny)
3
4plan <- drake_plan(
5 cars_data = mtcars,
6 deployment = custom_deployment_function(file_in("app.R"), cars_data)
7)
8
9custom_shiny_deployment <- function(file, data_input) {
10
11 rsconnect::deployApp(
12 appFiles = file,
13 appName = "cars",
14 forceUpdate = TRUE
15 )
16}
17
18Saved as "app.R" in project working directory (the app works outside of drake if data_input <- mtcars) :
19
20shinyApp(
21 ui = fluidPage(
22 selectInput("variable", "Variable:",
23 c("Cylinders" = "cyl",
24 "Transmission" = "am")),
25 tableOutput("data")
26 ),
27 server = function(input, output) {
28 output$data <- renderTable({
29 data_input[, c("mpg", input$variable), drop = FALSE]
30 }, rownames = TRUE)
31 }
32)
33
342020-07-14T20:12:57.418989+00:00 shinyapps[2569696]: htmltools version: 0.5.0
352020-07-14T20:12:57.419186+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
362020-07-14T20:12:57.589960+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
372020-07-14T20:12:57.593223+00:00 shinyapps[2569696]:
382020-07-14T20:12:57.593224+00:00 shinyapps[2569696]: Starting R with process ID: '25'
392020-07-14T20:12:57.628389+00:00 shinyapps[2569696]:
402020-07-14T20:12:57.628390+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:38608
412020-07-14T20:13:14.686424+00:00 shinyapps[2569696]: Running on host: e89f96d02b6e
422020-07-14T20:13:14.691423+00:00 shinyapps[2569696]: Server version: 1.8.4-11
432020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
442020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: R version: 4.0.0
452020-07-14T20:13:14.691437+00:00 shinyapps[2569696]: shiny version: 1.5.0
462020-07-14T20:13:14.691467+00:00 shinyapps[2569696]: rmarkdown version: (none)
472020-07-14T20:13:14.691648+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
482020-07-14T20:13:14.691475+00:00 shinyapps[2569696]: knitr version: (none)
492020-07-14T20:13:14.857243+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
502020-07-14T20:13:14.691443+00:00 shinyapps[2569696]: httpuv version: 1.5.4
512020-07-14T20:13:14.895595+00:00 shinyapps[2569696]:
522020-07-14T20:13:14.691480+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
532020-07-14T20:13:14.860404+00:00 shinyapps[2569696]:
542020-07-14T20:13:14.860404+00:00 shinyapps[2569696]: Starting R with process ID: '41'
552020-07-14T20:13:14.895596+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:42022
562020-07-14T20:13:14.691496+00:00 shinyapps[2569696]: RJSONIO version: (none)
572020-07-14T20:13:14.691506+00:00 shinyapps[2569696]: htmltools version: 0.5.0
582020-07-14T20:15:57.441648+00:00 shinyapps[2569696]: Running on host: a2e664ad9837
592020-07-14T20:15:57.447236+00:00 shinyapps[2569696]: Server version: 1.8.4-11
602020-07-14T20:15:57.447326+00:00 shinyapps[2569696]: R version: 4.0.0
612020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: knitr version: (none)
622020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: rmarkdown version: (none)
632020-07-14T20:15:57.447327+00:00 shinyapps[2569696]: shiny version: 1.5.0
642020-07-14T20:15:57.447260+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
652020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: httpuv version: 1.5.4
662020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
672020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: RJSONIO version: (none)
682020-07-14T20:15:57.667089+00:00 shinyapps[2569696]:
692020-07-14T20:15:57.447494+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
702020-07-14T20:15:57.630039+00:00 shinyapps[2569696]: Starting R with process ID: '24'
712020-07-14T20:15:57.626886+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
722020-07-14T20:15:57.447347+00:00 shinyapps[2569696]: htmltools version: 0.5.0
732020-07-14T20:15:57.630037+00:00 shinyapps[2569696]:
742020-07-14T20:15:57.667090+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:40107
752020-07-14T20:16:14.758082+00:00 shinyapps[2569696]: Warning: Error in renderTable: object 'data_input' not found
762020-07-14T20:16:14.772348+00:00 shinyapps[2569696]: 108: renderTable [/srv/connect/apps/cars/app.R#13]
772020-07-14T20:16:14.772349+00:00 shinyapps[2569696]: 107: func
782020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 94: origRenderFunc
792020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 93: output$data
802020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 13: runApp
812020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 12: fn
822020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 7: connect$retry
832020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 6: eval
842020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 5: eval
85library(shiny)
86
87cars_data <- readRDS("cars_data.RDS")
88
89shinyApp(
90 ui = fluidPage(
91 selectInput("variable", "Variable:",
92 c("Cylinders" = "cyl",
93 "Transmission" = "am")),
94 tableOutput("data")
95 ),
96 server = function(input, output) {
97 output$data <- renderTable({
98 cars_data[, c("mpg", input$variable), drop = FALSE]
99 }, rownames = TRUE)
100 }
101)
102library(drake)
103
104plan <- drake_plan(
105 cars_data = mtcars,
106 save_cars = saveRDS(cars_data, file_out("cars_data.RDS")),
107 deployment = rsconnect::deployApp(
108 appFiles = file_in("app.R", "cars_data.RDS"),
109 appName = "cars",
110 forceUpdate = TRUE
111 )
112)
113
114make(plan)
115
If you really want appFiles
to be NULL
, drake
still needs file_in()
so it knows to depend on physical files.
1library(drake)
2library(shiny)
3
4plan <- drake_plan(
5 cars_data = mtcars,
6 deployment = custom_deployment_function(file_in("app.R"), cars_data)
7)
8
9custom_shiny_deployment <- function(file, data_input) {
10
11 rsconnect::deployApp(
12 appFiles = file,
13 appName = "cars",
14 forceUpdate = TRUE
15 )
16}
17
18Saved as "app.R" in project working directory (the app works outside of drake if data_input <- mtcars) :
19
20shinyApp(
21 ui = fluidPage(
22 selectInput("variable", "Variable:",
23 c("Cylinders" = "cyl",
24 "Transmission" = "am")),
25 tableOutput("data")
26 ),
27 server = function(input, output) {
28 output$data <- renderTable({
29 data_input[, c("mpg", input$variable), drop = FALSE]
30 }, rownames = TRUE)
31 }
32)
33
342020-07-14T20:12:57.418989+00:00 shinyapps[2569696]: htmltools version: 0.5.0
352020-07-14T20:12:57.419186+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
362020-07-14T20:12:57.589960+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
372020-07-14T20:12:57.593223+00:00 shinyapps[2569696]:
382020-07-14T20:12:57.593224+00:00 shinyapps[2569696]: Starting R with process ID: '25'
392020-07-14T20:12:57.628389+00:00 shinyapps[2569696]:
402020-07-14T20:12:57.628390+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:38608
412020-07-14T20:13:14.686424+00:00 shinyapps[2569696]: Running on host: e89f96d02b6e
422020-07-14T20:13:14.691423+00:00 shinyapps[2569696]: Server version: 1.8.4-11
432020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
442020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: R version: 4.0.0
452020-07-14T20:13:14.691437+00:00 shinyapps[2569696]: shiny version: 1.5.0
462020-07-14T20:13:14.691467+00:00 shinyapps[2569696]: rmarkdown version: (none)
472020-07-14T20:13:14.691648+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
482020-07-14T20:13:14.691475+00:00 shinyapps[2569696]: knitr version: (none)
492020-07-14T20:13:14.857243+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
502020-07-14T20:13:14.691443+00:00 shinyapps[2569696]: httpuv version: 1.5.4
512020-07-14T20:13:14.895595+00:00 shinyapps[2569696]:
522020-07-14T20:13:14.691480+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
532020-07-14T20:13:14.860404+00:00 shinyapps[2569696]:
542020-07-14T20:13:14.860404+00:00 shinyapps[2569696]: Starting R with process ID: '41'
552020-07-14T20:13:14.895596+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:42022
562020-07-14T20:13:14.691496+00:00 shinyapps[2569696]: RJSONIO version: (none)
572020-07-14T20:13:14.691506+00:00 shinyapps[2569696]: htmltools version: 0.5.0
582020-07-14T20:15:57.441648+00:00 shinyapps[2569696]: Running on host: a2e664ad9837
592020-07-14T20:15:57.447236+00:00 shinyapps[2569696]: Server version: 1.8.4-11
602020-07-14T20:15:57.447326+00:00 shinyapps[2569696]: R version: 4.0.0
612020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: knitr version: (none)
622020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: rmarkdown version: (none)
632020-07-14T20:15:57.447327+00:00 shinyapps[2569696]: shiny version: 1.5.0
642020-07-14T20:15:57.447260+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
652020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: httpuv version: 1.5.4
662020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
672020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: RJSONIO version: (none)
682020-07-14T20:15:57.667089+00:00 shinyapps[2569696]:
692020-07-14T20:15:57.447494+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
702020-07-14T20:15:57.630039+00:00 shinyapps[2569696]: Starting R with process ID: '24'
712020-07-14T20:15:57.626886+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
722020-07-14T20:15:57.447347+00:00 shinyapps[2569696]: htmltools version: 0.5.0
732020-07-14T20:15:57.630037+00:00 shinyapps[2569696]:
742020-07-14T20:15:57.667090+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:40107
752020-07-14T20:16:14.758082+00:00 shinyapps[2569696]: Warning: Error in renderTable: object 'data_input' not found
762020-07-14T20:16:14.772348+00:00 shinyapps[2569696]: 108: renderTable [/srv/connect/apps/cars/app.R#13]
772020-07-14T20:16:14.772349+00:00 shinyapps[2569696]: 107: func
782020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 94: origRenderFunc
792020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 93: output$data
802020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 13: runApp
812020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 12: fn
822020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 7: connect$retry
832020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 6: eval
842020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 5: eval
85library(shiny)
86
87cars_data <- readRDS("cars_data.RDS")
88
89shinyApp(
90 ui = fluidPage(
91 selectInput("variable", "Variable:",
92 c("Cylinders" = "cyl",
93 "Transmission" = "am")),
94 tableOutput("data")
95 ),
96 server = function(input, output) {
97 output$data <- renderTable({
98 cars_data[, c("mpg", input$variable), drop = FALSE]
99 }, rownames = TRUE)
100 }
101)
102library(drake)
103
104plan <- drake_plan(
105 cars_data = mtcars,
106 save_cars = saveRDS(cars_data, file_out("cars_data.RDS")),
107 deployment = rsconnect::deployApp(
108 appFiles = file_in("app.R", "cars_data.RDS"),
109 appName = "cars",
110 forceUpdate = TRUE
111 )
112)
113
114make(plan)
115plan <- drake_plan(
116 cars_data = mtcars,
117 save_cars = saveRDS(cars_data, file_out("cars_data.RDS")),
118 deployment = deploy_app(file_in("cars_data.RDS", "app.R"))
119)
120
121deploy_app <- function(...) {
122 rsconnect::deployApp(
123 appFiles = NULL,
124 appName = "cars",
125 forceUpdate = TRUE
126 )
127}
128
Either way, I recommend checking the plan with plot()
or vis_drake_graph()
before you run it with make()
. Both plans above show deployment
downstream of the data file (with incoming arrows) which is exactly what we want.
1library(drake)
2library(shiny)
3
4plan <- drake_plan(
5 cars_data = mtcars,
6 deployment = custom_deployment_function(file_in("app.R"), cars_data)
7)
8
9custom_shiny_deployment <- function(file, data_input) {
10
11 rsconnect::deployApp(
12 appFiles = file,
13 appName = "cars",
14 forceUpdate = TRUE
15 )
16}
17
18Saved as "app.R" in project working directory (the app works outside of drake if data_input <- mtcars) :
19
20shinyApp(
21 ui = fluidPage(
22 selectInput("variable", "Variable:",
23 c("Cylinders" = "cyl",
24 "Transmission" = "am")),
25 tableOutput("data")
26 ),
27 server = function(input, output) {
28 output$data <- renderTable({
29 data_input[, c("mpg", input$variable), drop = FALSE]
30 }, rownames = TRUE)
31 }
32)
33
342020-07-14T20:12:57.418989+00:00 shinyapps[2569696]: htmltools version: 0.5.0
352020-07-14T20:12:57.419186+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
362020-07-14T20:12:57.589960+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
372020-07-14T20:12:57.593223+00:00 shinyapps[2569696]:
382020-07-14T20:12:57.593224+00:00 shinyapps[2569696]: Starting R with process ID: '25'
392020-07-14T20:12:57.628389+00:00 shinyapps[2569696]:
402020-07-14T20:12:57.628390+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:38608
412020-07-14T20:13:14.686424+00:00 shinyapps[2569696]: Running on host: e89f96d02b6e
422020-07-14T20:13:14.691423+00:00 shinyapps[2569696]: Server version: 1.8.4-11
432020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
442020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: R version: 4.0.0
452020-07-14T20:13:14.691437+00:00 shinyapps[2569696]: shiny version: 1.5.0
462020-07-14T20:13:14.691467+00:00 shinyapps[2569696]: rmarkdown version: (none)
472020-07-14T20:13:14.691648+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
482020-07-14T20:13:14.691475+00:00 shinyapps[2569696]: knitr version: (none)
492020-07-14T20:13:14.857243+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
502020-07-14T20:13:14.691443+00:00 shinyapps[2569696]: httpuv version: 1.5.4
512020-07-14T20:13:14.895595+00:00 shinyapps[2569696]:
522020-07-14T20:13:14.691480+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
532020-07-14T20:13:14.860404+00:00 shinyapps[2569696]:
542020-07-14T20:13:14.860404+00:00 shinyapps[2569696]: Starting R with process ID: '41'
552020-07-14T20:13:14.895596+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:42022
562020-07-14T20:13:14.691496+00:00 shinyapps[2569696]: RJSONIO version: (none)
572020-07-14T20:13:14.691506+00:00 shinyapps[2569696]: htmltools version: 0.5.0
582020-07-14T20:15:57.441648+00:00 shinyapps[2569696]: Running on host: a2e664ad9837
592020-07-14T20:15:57.447236+00:00 shinyapps[2569696]: Server version: 1.8.4-11
602020-07-14T20:15:57.447326+00:00 shinyapps[2569696]: R version: 4.0.0
612020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: knitr version: (none)
622020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: rmarkdown version: (none)
632020-07-14T20:15:57.447327+00:00 shinyapps[2569696]: shiny version: 1.5.0
642020-07-14T20:15:57.447260+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
652020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: httpuv version: 1.5.4
662020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
672020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: RJSONIO version: (none)
682020-07-14T20:15:57.667089+00:00 shinyapps[2569696]:
692020-07-14T20:15:57.447494+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
702020-07-14T20:15:57.630039+00:00 shinyapps[2569696]: Starting R with process ID: '24'
712020-07-14T20:15:57.626886+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
722020-07-14T20:15:57.447347+00:00 shinyapps[2569696]: htmltools version: 0.5.0
732020-07-14T20:15:57.630037+00:00 shinyapps[2569696]:
742020-07-14T20:15:57.667090+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:40107
752020-07-14T20:16:14.758082+00:00 shinyapps[2569696]: Warning: Error in renderTable: object 'data_input' not found
762020-07-14T20:16:14.772348+00:00 shinyapps[2569696]: 108: renderTable [/srv/connect/apps/cars/app.R#13]
772020-07-14T20:16:14.772349+00:00 shinyapps[2569696]: 107: func
782020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 94: origRenderFunc
792020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 93: output$data
802020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 13: runApp
812020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 12: fn
822020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 7: connect$retry
832020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 6: eval
842020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 5: eval
85library(shiny)
86
87cars_data <- readRDS("cars_data.RDS")
88
89shinyApp(
90 ui = fluidPage(
91 selectInput("variable", "Variable:",
92 c("Cylinders" = "cyl",
93 "Transmission" = "am")),
94 tableOutput("data")
95 ),
96 server = function(input, output) {
97 output$data <- renderTable({
98 cars_data[, c("mpg", input$variable), drop = FALSE]
99 }, rownames = TRUE)
100 }
101)
102library(drake)
103
104plan <- drake_plan(
105 cars_data = mtcars,
106 save_cars = saveRDS(cars_data, file_out("cars_data.RDS")),
107 deployment = rsconnect::deployApp(
108 appFiles = file_in("app.R", "cars_data.RDS"),
109 appName = "cars",
110 forceUpdate = TRUE
111 )
112)
113
114make(plan)
115plan <- drake_plan(
116 cars_data = mtcars,
117 save_cars = saveRDS(cars_data, file_out("cars_data.RDS")),
118 deployment = deploy_app(file_in("cars_data.RDS", "app.R"))
119)
120
121deploy_app <- function(...) {
122 rsconnect::deployApp(
123 appFiles = NULL,
124 appName = "cars",
125 forceUpdate = TRUE
126 )
127}
128plot(plan)
129
Without these file markers, there is a chance that drake
will deploy the app before the data is ready to go.
1library(drake)
2library(shiny)
3
4plan <- drake_plan(
5 cars_data = mtcars,
6 deployment = custom_deployment_function(file_in("app.R"), cars_data)
7)
8
9custom_shiny_deployment <- function(file, data_input) {
10
11 rsconnect::deployApp(
12 appFiles = file,
13 appName = "cars",
14 forceUpdate = TRUE
15 )
16}
17
18Saved as "app.R" in project working directory (the app works outside of drake if data_input <- mtcars) :
19
20shinyApp(
21 ui = fluidPage(
22 selectInput("variable", "Variable:",
23 c("Cylinders" = "cyl",
24 "Transmission" = "am")),
25 tableOutput("data")
26 ),
27 server = function(input, output) {
28 output$data <- renderTable({
29 data_input[, c("mpg", input$variable), drop = FALSE]
30 }, rownames = TRUE)
31 }
32)
33
342020-07-14T20:12:57.418989+00:00 shinyapps[2569696]: htmltools version: 0.5.0
352020-07-14T20:12:57.419186+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
362020-07-14T20:12:57.589960+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
372020-07-14T20:12:57.593223+00:00 shinyapps[2569696]:
382020-07-14T20:12:57.593224+00:00 shinyapps[2569696]: Starting R with process ID: '25'
392020-07-14T20:12:57.628389+00:00 shinyapps[2569696]:
402020-07-14T20:12:57.628390+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:38608
412020-07-14T20:13:14.686424+00:00 shinyapps[2569696]: Running on host: e89f96d02b6e
422020-07-14T20:13:14.691423+00:00 shinyapps[2569696]: Server version: 1.8.4-11
432020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
442020-07-14T20:13:14.691436+00:00 shinyapps[2569696]: R version: 4.0.0
452020-07-14T20:13:14.691437+00:00 shinyapps[2569696]: shiny version: 1.5.0
462020-07-14T20:13:14.691467+00:00 shinyapps[2569696]: rmarkdown version: (none)
472020-07-14T20:13:14.691648+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
482020-07-14T20:13:14.691475+00:00 shinyapps[2569696]: knitr version: (none)
492020-07-14T20:13:14.857243+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
502020-07-14T20:13:14.691443+00:00 shinyapps[2569696]: httpuv version: 1.5.4
512020-07-14T20:13:14.895595+00:00 shinyapps[2569696]:
522020-07-14T20:13:14.691480+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
532020-07-14T20:13:14.860404+00:00 shinyapps[2569696]:
542020-07-14T20:13:14.860404+00:00 shinyapps[2569696]: Starting R with process ID: '41'
552020-07-14T20:13:14.895596+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:42022
562020-07-14T20:13:14.691496+00:00 shinyapps[2569696]: RJSONIO version: (none)
572020-07-14T20:13:14.691506+00:00 shinyapps[2569696]: htmltools version: 0.5.0
582020-07-14T20:15:57.441648+00:00 shinyapps[2569696]: Running on host: a2e664ad9837
592020-07-14T20:15:57.447236+00:00 shinyapps[2569696]: Server version: 1.8.4-11
602020-07-14T20:15:57.447326+00:00 shinyapps[2569696]: R version: 4.0.0
612020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: knitr version: (none)
622020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: rmarkdown version: (none)
632020-07-14T20:15:57.447327+00:00 shinyapps[2569696]: shiny version: 1.5.0
642020-07-14T20:15:57.447260+00:00 shinyapps[2569696]: LANG: en_US.UTF-8
652020-07-14T20:15:57.447337+00:00 shinyapps[2569696]: httpuv version: 1.5.4
662020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: jsonlite version: 1.7.0
672020-07-14T20:15:57.447338+00:00 shinyapps[2569696]: RJSONIO version: (none)
682020-07-14T20:15:57.667089+00:00 shinyapps[2569696]:
692020-07-14T20:15:57.447494+00:00 shinyapps[2569696]: Using pandoc: /opt/connect/ext/pandoc2
702020-07-14T20:15:57.630039+00:00 shinyapps[2569696]: Starting R with process ID: '24'
712020-07-14T20:15:57.626886+00:00 shinyapps[2569696]: Using jsonlite for JSON processing
722020-07-14T20:15:57.447347+00:00 shinyapps[2569696]: htmltools version: 0.5.0
732020-07-14T20:15:57.630037+00:00 shinyapps[2569696]:
742020-07-14T20:15:57.667090+00:00 shinyapps[2569696]: Listening on http://127.0.0.1:40107
752020-07-14T20:16:14.758082+00:00 shinyapps[2569696]: Warning: Error in renderTable: object 'data_input' not found
762020-07-14T20:16:14.772348+00:00 shinyapps[2569696]: 108: renderTable [/srv/connect/apps/cars/app.R#13]
772020-07-14T20:16:14.772349+00:00 shinyapps[2569696]: 107: func
782020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 94: origRenderFunc
792020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 93: output$data
802020-07-14T20:16:14.772350+00:00 shinyapps[2569696]: 13: runApp
812020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 12: fn
822020-07-14T20:16:14.772351+00:00 shinyapps[2569696]: 7: connect$retry
832020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 6: eval
842020-07-14T20:16:14.772352+00:00 shinyapps[2569696]: 5: eval
85library(shiny)
86
87cars_data <- readRDS("cars_data.RDS")
88
89shinyApp(
90 ui = fluidPage(
91 selectInput("variable", "Variable:",
92 c("Cylinders" = "cyl",
93 "Transmission" = "am")),
94 tableOutput("data")
95 ),
96 server = function(input, output) {
97 output$data <- renderTable({
98 cars_data[, c("mpg", input$variable), drop = FALSE]
99 }, rownames = TRUE)
100 }
101)
102library(drake)
103
104plan <- drake_plan(
105 cars_data = mtcars,
106 save_cars = saveRDS(cars_data, file_out("cars_data.RDS")),
107 deployment = rsconnect::deployApp(
108 appFiles = file_in("app.R", "cars_data.RDS"),
109 appName = "cars",
110 forceUpdate = TRUE
111 )
112)
113
114make(plan)
115plan <- drake_plan(
116 cars_data = mtcars,
117 save_cars = saveRDS(cars_data, file_out("cars_data.RDS")),
118 deployment = deploy_app(file_in("cars_data.RDS", "app.R"))
119)
120
121deploy_app <- function(...) {
122 rsconnect::deployApp(
123 appFiles = NULL,
124 appName = "cars",
125 forceUpdate = TRUE
126 )
127}
128plot(plan)
129disconnected_plan <- drake_plan(
130 cars_data = mtcars,
131 saveRDS(cars_data, "cars_data.RDS"),
132 deployment = rsconnect::deployApp(
133 appFiles = NULL,
134 appName = "cars",
135 forceUpdate = TRUE
136 )
137)
138
139plot(disconnected_plan)
140
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in JSON Processing
Tutorials and Learning Resources are not available at this moment for JSON Processing